Sign in to follow this  
Followers 0
realkiller

filewrite

14 posts in this topic




#4 ·  Posted (edited)

do you know backspace 2?

@BS

Edit

Seriously you could open the file for editing and do a ControlSend

Edited by BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Could you please explain what exactly you want to do? Figuring out how to help you from reading your post is like trying to decipher encypted Swahili with only a used napkin and an abacus.

Share this post


Link to post
Share on other sites

He doesn't want to write a backspace character, he wants to remove text from the end of a line in a file.


Who else would I be?

Share this post


Link to post
Share on other sites

You can't write a backspace to a file.** You will need to read the entire file into memory, chop off the last character and then write the file back to disk.

Something like this should do what you want:

; define location of file
 local $file = "C:\MyFile.txt"
 
; read file into a variable
 local $data = fileRead($file, fileGetSize($file))
 
; remove final character
 $data = stringTrimRight($data, 1)
 
; write it back
; you may not have to delete the file first (documentation says it will 'append')
 fileDelete($file)
 fileWrite($file, $data)

** Technically you can append a character with ASCII code 8, but this certainly won't do what you expect.

Share this post


Link to post
Share on other sites

Well, it does -- I just tested it. It depends on what's at the end of your file.

Are you trying to remove a line break? Generally a line break is two bytes long for DOS/Windows files (a CR byte and an LF byte). If you're trying to remove such a sequence then you'll need to modify the above script to remove the last two characters. Try that and let us know.

We are talking about manipulating a plain text file, right?

Share this post


Link to post
Share on other sites

I think I know what's going on -- you want the last character to be removed from a file that's open and displayed. File manipulation won't help you with that.

My code will however do what it states. If you run the code and then re-open the file, the character will be gone. If you really want to remove the character from the open file though, then you'll need to write a script that sends Ctrl+End, Backspace and Ctrl+S to the window that has the document in it. (The keys should respectively perform end-of-file, remove character and save document.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0