leuce Posted March 7, 2006 Share 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. Link to comment Share on other sites More sharing options...
pecloe Posted March 7, 2006 Share 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 Link to comment Share on other sites More sharing options...
leuce Posted March 7, 2006 Author Share 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. Link to comment Share on other sites More sharing options...
pecloe Posted March 7, 2006 Share 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) Link to comment Share on other sites More sharing options...
leuce Posted March 7, 2006 Author Share Posted March 7, 2006 " 2 = Write mode (erase previous contents) "Thanks... I didn't see your <<<<<<<<<< in the previous post. Link to comment Share on other sites More sharing options...
Valuater Posted March 7, 2006 Share 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) Link to comment Share on other sites More sharing options...
=sinister= Posted March 7, 2006 Share Posted March 7, 2006 look at this script - http://www.autoitscript.com/forum/index.ph...topic=21797&hl= Link to comment Share on other sites More sharing options...
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