Jump to content

Read txt


cleston
 Share

Recommended Posts

I'm very new at autoit (just did the basic tutorials) and not much of a programmer, so forgive the probably trivial/poorly stated question:

I wanted to open the most recent .txt in a folder full of other .txt documents and put its info in a variable so I can work with it withing autoit. I want to avoid explicitly opening the document and using clipboard (this is the only solution I could think of).

So, is there a function to read a txt directly? Any suggestions on reading the file by date and not by name?

Thanks in advance!

Link to comment
Share on other sites

You can use FileGetTime() to determine the most recent folder. See help file.

To read the entire contents to a variable use FileRead(). The first parameter can be an open file handle, but it doesn't have to be. You can just use the file path and read the whole file at once.

:x

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you, PsaltyDS, that was very helpful, FileRead() was exactly what I was looking for.

As for FileGetTime(), I'm not sure how to use it. The thing is that it requires a filename or handle and my difficulty is precisely in getting one of the two. All that I know is the folder where the file is and that I want to open the most recent file. Did you have something in mind?

Perhaps this should be a windows functionality rather than an autoit function? I'm using windows 7, btw.

Link to comment
Share on other sites

Couple of functions you might want to look at are

FileFindFirstFile() and its related functions FileClose(), and FileFindNextFile(). and loop through the folder checking the dates with the suggested function.

You could also look at _FileListToArray() and loop through a resulting array.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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