Jump to content

How to overwrite a file


Recommended Posts

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

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 by pecloe
Link to comment
Share on other sites

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

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)

NEWHeader1.png

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...