Thudo Posted May 12, 2010 Share Posted May 12, 2010 Problem: in AutoIT I want the script to do the following: 1) Locate a randomly generated filename in a specific folder.. (ie. C:\Program Files\test_application\tmp\<where random filename is created> 2) Report ONLY the first filename that it find and what it is called "ie. test_001.tmp" 3) Output this to a script so I can reference it in a command line path. Every other AutoIT script function seems to report a result if something exists or not and NOT the filename itself. FileFindFirstFile is like that where it just tells you 1 for YES its present or -1 for NO. I simply need a facility to go look on a path, see what the first filename is there, and dump that name for use elsewhere. I could not find any help anywhere for this and its my last AutoIT script challenge to figure out. Thanks everyone! Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 12, 2010 Share Posted May 12, 2010 FileFindFirstFile() returns a search handle. Do FileFindNextFile() after it and you get the first file found. 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 More sharing options...
Thudo Posted May 12, 2010 Author Share Posted May 12, 2010 (edited) That returns a -1 or 1 and NOT the actual filename itself. I need something like: $indfile=FileFindFirstFile("C:\Program Files\test_application\tmp\*.tmp") $file = FileFindNextFile($indfile) So when I call $file its the actual filename and not a result code like -1 or 1. Btw, thank you Psaltyus for the prompt reply. I really need this figured out and found no help anywhere for it. Edited May 12, 2010 by Thudo Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 12, 2010 Share Posted May 12, 2010 (edited) Review FileFindFirstFile() and FileFindNextFile() again in the help file. FileFindFirstFile() returns -1 if no first match is found, otherwise it returns a handle. That handle can then be used with FileFindNextFile() to get the actual file names. Assuming you get a valid handle in the first place, the first time you run FileFindNextFile() with that handle you get the first file name. $hSearch = FileFindFirstFile("C:\Program Files\test_application\tmp\*.tmp") If $hSearch <> -1 Then $sFile = FileFindNextFile($hSearch) MsgBox(64, "Found", "Fist file = " & $sFile) Else MsgBox(16, "Error", "No matching files") EndIf Edit: Typo Edited May 12, 2010 by PsaltyDS 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 More sharing options...
zorphnog Posted May 12, 2010 Share Posted May 12, 2010 From helpfile: Return Value Success: Returns a filename according to a previous call to FileFindFirstFile, @extended set to 1 if filename is a directory. Failure: Sets @error to 1 if no more files/directories match the search. We've all used FileFindNextFile many times. It returns a filename. Link to comment Share on other sites More sharing options...
Thudo Posted May 12, 2010 Author Share Posted May 12, 2010 (edited) Yeah sorry it works perfectly and have it doing its magic. Thanks AutoIT staff and community for your patience Final code line: $indfile = FileFindFirstFile("C:\Program Files\test_application\tmp\*.tmp") $resultfile = FileFindNextFile($indfile) Then I just call $resultfile and all it peachy! Edited May 12, 2010 by Thudo Link to comment Share on other sites More sharing options...
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