Help with %A_BACKSPACE% Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
asdads
Posts: 13
Joined: 07 Feb 2018, 09:45

Help with %A_BACKSPACE%

04 Apr 2018, 16:21

Hello ! :D

How can i do when i press F1 it´s delete the First letter of my Text File. Example

Code: Select all

F1::
FileAppend, %A_BACKSPACE%, myfile.txt
return
It´s doesn´t work and i don´t know why ? thx ;)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with %A_BACKSPACE%

04 Apr 2018, 17:53

- Here's a way to remove the first character from a text file:

Code: Select all

;note: use FileOpen/FileDelete/FileAppend with caution, as they can alter file content
;backup any important files before testing

q:: ;remove first character from text file
;create test file
vPath := A_Desktop "\MyUtf8File.txt", vEnc := "UTF-8"
;vPath := A_Desktop "\MyUtf16File.txt", vEnc := "UTF-16"
;vPath := A_Desktop "\MyAnsiFile.txt", vEnc := "CP0"
if !FileExist(vPath)
	FileAppend, % "abcde", % "*" vPath, % vEnc

;check if file exists
if !FileExist(vPath)
	return

;get encoding
if !(oFile := FileOpen(vPath, "r"))
	return
vEnc := oFile.Encoding
oFile.Close()

;get text
FileRead, vText, % vPath

;delete file
FileDelete, % vPath

;append text
FileAppend, % SubStr(vText, 2), % "*" vPath, % vEnc

;open file
Run, % vPath
return

;note: to remove 1 character each time:
;SubStr(vText, 1, -1)
- Btw, if I wanted to suggest a way of removing the first character from a text file, via FileAppend, that I knew wouldn't work, it would involve Ctrl+Home and Del, not Backspace. Although admittedly Ctrl+Home, Right, Backspace would be another possibility.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
asdads
Posts: 13
Joined: 07 Feb 2018, 09:45

Re: Help with %A_BACKSPACE%  Topic is solved

05 Apr 2018, 05:36

jeeswg wrote:- Here's a way to remove the first character from a text file:

Code: Select all

;note: use FileOpen/FileDelete/FileAppend with caution, as they can alter file content
;backup any important files before testing

q:: ;remove first character from text file
;create test file
vPath := A_Desktop "\MyUtf8File.txt", vEnc := "UTF-8"
;vPath := A_Desktop "\MyUtf16File.txt", vEnc := "UTF-16"
;vPath := A_Desktop "\MyAnsiFile.txt", vEnc := "CP0"
if !FileExist(vPath)
	FileAppend, % "abcde", % "*" vPath, % vEnc

;check if file exists
if !FileExist(vPath)
	return

;get encoding
if !(oFile := FileOpen(vPath, "r"))
	return
vEnc := oFile.Encoding
oFile.Close()

;get text
FileRead, vText, % vPath

;delete file
FileDelete, % vPath

;append text
FileAppend, % SubStr(vText, 2), % "*" vPath, % vEnc

;open file
Run, % vPath
return

;note: to remove 1 character each time:
;SubStr(vText, 1, -1)
- Btw, if I wanted to suggest a way of removing the first character from a text file, via FileAppend, that I knew wouldn't work, it would involve Ctrl+Home and Del, not Backspace. Although admittedly Ctrl+Home, Right, Backspace would be another possibility.
Thank you very much it´s worked :superhappy:
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: Help with %A_BACKSPACE%

05 Apr 2018, 07:53

asdads wrote:- Btw, if I wanted to suggest a way of removing the first character from a text file, via FileAppend, that I knew wouldn't work, it would involve Ctrl+Home and Del, not Backspace. Although admittedly Ctrl+Home, Right, Backspace would be another possibility.
Do you think it would work that way? Shortcuts works on opened file.
His code never supposed to work, since it don't perform any action on text.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with %A_BACKSPACE%

05 Apr 2018, 11:45

- If you have the text open in Notepad, two possibilities to delete the first character:

Code: Select all

;delete first character in Notepad
q::SendInput, ^{Home}{Del}
w::SendInput, ^{Home}{Right}{Backspace}
- Btw deleting the first character seems pretty unusual. Are there good uses for it? Deleting an entire line, or reading/writing to/from an ini seem more common (if just a few characters are being used).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: Help with %A_BACKSPACE%

05 Apr 2018, 23:16

Alright @jeeswg it's obvious :)
... But he was FileAppending :P

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], TablePerson22, TAC109 and 35 guests