Jump to content

write a variable to a new txt file in a dir


 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

<{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 by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

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'

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