Jump to content

filewrite


realkiller
 Share

Recommended Posts

  • Developers

Enter is a key on the keyboard.. do you mean the @CRLF characters ?

filewrite ("lol.txt", @crlf)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

do you know backspace 2?

@BS

Edit

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

Edited by BigDod


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

Link to comment
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.

Link to comment
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?

Link to comment
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.)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...