Sign in to follow this  
Followers 0
jbennett

Where can I find info about write to a txt file?

20 posts in this topic

Hey,

Does anyone know where I can find some info on writing to a text file?

Just want my code to log the date and computer name in a .txt file

thanks

Share this post


Link to post
Share on other sites



FileOpen()

FileWrite()

FileClose()

:P

Share this post


Link to post
Share on other sites

cheers ;-)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The only problem I have with this is:

FileWrite($file, "Line1")

FileWrite($file, "Still Line1" & @CRLF)

FileWrite($file, "Line2")

I want my application to always use the next line. Hmmm

Any ideas? thanks

Main purpose is a log file.

Edited by jbennett

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Share this post


Link to post
Share on other sites

filewriteline() does the job very nicely.

Is there any way I can include the name of the computer in the code?

thanks

Share this post


Link to post
Share on other sites

got it...

$computername = EnvGet("computername")

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Forgot to mention.

This log file will be on a server and a couple of PCs may access it at the same time.

Can this possibly work?

I'm wondering if I can put some sort of wait command in the code so that the code will wait if another user is accessing it.

thanks

Edited by jbennett

Share this post


Link to post
Share on other sites

It can but if it's on a server the best thing would be to have a database, also it's incredibly rude to triple post. Edit your posts,don't make new ones.

Share this post


Link to post
Share on other sites

Sorry, I will remember to edit my posts from now on

I see what you're saying about a database but just want to keep it simple :-)

Share this post


Link to post
Share on other sites

Well if the file is only going to be accessed and not edited then you should be fine as is but if you're going to edit it then yeah you should go for a database. They're not as hard as you think.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Oh my. Do you mean a database with access?

I've never worked with a database before :-(

Edited by jbennett

Share this post


Link to post
Share on other sites

Check out using this- http://www.autoitscript.com/forum/index.php?showtopic=20814

There are many other databases available on the forum.

Your other option is to have a server write the logs, and your clients tell the server what to write. If you wish to do that, check out Kip's TCP On Event script- http://www.autoitscript.com/forum/index.php?showtopic=74325

Cheers,

Brett

Share this post


Link to post
Share on other sites

My script is very simple and just runs a backup program.

The log just records the users computer name and the date and time.

Share this post


Link to post
Share on other sites

I have MySQL setup for the forums on my website but most SQL databases should be functionally the same. There are built in functions for SQLite and there's a UDF for MySQL. As long as you know the syntax of the commands you need you'll be fine.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Ummm my brain can't handle that code tonight :-(

I still feel like using the txt file, mainly because the code is very simple and there will only be about 3 entry's per every 2 weeks.

Just want to get a simple idea in place that I can try tomorrow. It's 1:31am here now, OUCH

Sorry, hope i'm not being a pain.

Edited by jbennett

Share this post


Link to post
Share on other sites

If it's going to be that infrequent you should be ok with a text file. A database works better for multiple simultaneous connections and I thought that's what you were doing.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Nah it's very basic.

Just for my own personal use to see if it's actually working on client PCs.

Want to be sure that if 2 PCs are running it then they will both put in the info, even if running the schedule at the same time. Mainly will be about 3 PCs per every 2 weeks though, just trying to be safe.

Just can't find the code in the help files to wait for txt file to close before writting to it.

Cheers

Edited by jbennett

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I come up with an idea, considering I would only have 3 PCs

$computername = EnvGet("computername")

$file = FileOpen(@Scriptdir & "-" & $computername & ".txt", 1)

Seems to put the @scriptdir in the file name though lol, but almost there.

cheers

UPDATE

--------

Figured it out

$computername = EnvGet("computername")

$file = FileOpen(@Scriptdir & "\" & "Backup_Log" & "-" & $computername & ".txt", 1)

Edited by jbennett

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