leuce Posted March 7, 2006 Posted March 7, 2006 G'day everyone I know that I can open a file with FileOpen, and that I can append to that file using FileWrite, but how do I overwrite an existing file with a new, empty file, so that whatever I write to it, is the only thing that is written to it? One method might be to tell AutoIt to delete the original file before executing a FileOpen (which will then create the file), but is there a way to simply create a file and save it and not get an error message even though the file already exists? Thanks Samuel PS There's no code yet, but I'll post it when I write it.
pecloe Posted March 7, 2006 Posted March 7, 2006 (edited) FileOpen ( "filename", mode ) Parameters filename Filename of the text file to open. mode Mode (read or write) to open the file in. 0 = Read mode 1 = Write mode (append to end of file) 2 = Write mode (erase previous contents) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Both write modes will create the file if it does not already exist. not quite what you want Edited March 7, 2006 by pecloe
leuce Posted March 7, 2006 Author Posted March 7, 2006 Both write modes will create the file if it does not already exist.Let me explain. There is already a file named Foo.txt in the folder. I want AutoIt to create a new file called Foo.txt and overwrite the existing file Foo.txt without asking. Or to put it a different way: I want AutoIt to open the file Foo.txt and overwrite (not append) the existing contents with new content.
pecloe Posted March 7, 2006 Posted March 7, 2006 " 2 = Write mode (erase previous contents) " since foo.txt already exists mode 2 will overwrite without a prompt (at least in production)
leuce Posted March 7, 2006 Author Posted March 7, 2006 " 2 = Write mode (erase previous contents) "Thanks... I didn't see your <<<<<<<<<< in the previous post.
Valuater Posted March 7, 2006 Posted March 7, 2006 lots of times i just delete the previous file or create a backup copy FileDelete(@ScriptDir & "\Address.bak") FileCopy(@ScriptDir & "\Address.ini, @ScriptDir & "\Address.bak", 1) FileDelete(@ScriptDir & "\Address.ini") FileWriteLine(@ScriptDir & "\Address.ini, "[Address]") 8)
=sinister= Posted March 7, 2006 Posted March 7, 2006 look at this script - http://www.autoitscript.com/forum/index.ph...topic=21797&hl=
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now