GZE Posted July 26, 2005 Posted July 26, 2005 Hello, I would like to create a new text file in a specific dir with a specific text (or variable) in it. Can this be done directly something like SendStringTofile :s or do I have to use a workaround like opening notepad? Kind regard, GZE
Leopardfist Posted July 26, 2005 Posted July 26, 2005 #include <file.au3> If fileexists("<your preferred file directory you wish to create>") then msgbox(0, "", "File already exists") Else _FileCreate ( "<your preferred file directory you wish to create>") EndIf The reason for the If then statement is that IF the file already exists, the _Filecreate command will delete all of the data in the file. You could change the statement to Filewrite command if the file exists to add data to it! Lots of File commands you can check out in the html help file that comes with autoit... you can do just about anything you want to.
FuryCell Posted July 26, 2005 Posted July 26, 2005 (edited) #include <file.au3>If fileexists("<your preferred file directory you wish to create>") thenmsgbox(0, "", "File already exists")Else_FileCreate ( "<your preferred file directory you wish to create>")EndIfThe reason for the If then statement is that IF the file already exists, the _Filecreate command will delete all of the data in the file. You could change the statement to Filewrite command if the file exists to add data to it!Lots of File commands you can check out in the html help file that comes with autoit... you can do just about anything you want to.<{POST_SNAPBACK}>Why not just do:$File=FileOpen(<File of choice>,2) FileWrite($File,$Value) FileClose($File)This works becuase becuase 2 means:Write mode (erase previous contents) Edited July 26, 2005 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
seandisanti Posted July 26, 2005 Posted July 26, 2005 FileWrite( "C:\folder\filename.txt", $sValue ) <{POST_SNAPBACK}>personally i'd be more likely to use:$myfile = FileOpen("C:\blah.txt",1) FileWriteLine($myfile,$value)so that if the file is already there, the new data is appended (unless you want it overwritten, in which case replace the ',1' with a ',2'
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