Sign in to follow this  
Followers 0
GZE

write a variable to a new txt file in a dir

5 posts in this topic

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

Share this post


Link to post
Share on other sites



FileWrite( "C:\folder\filename.txt", $sValue )

:)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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'


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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
Sign in to follow this  
Followers 0