Jump to content
Sign in to follow this  
Thudo

How to detect filename in a folder then report it?

Recommended Posts

Thudo

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!

Share this post


Link to post
Share on other sites
PsaltyDS

FileFindFirstFile() returns a search handle. Do FileFindNextFile() after it and you get the first file found.

:idea:


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

Share this post


Link to post
Share on other sites
Thudo

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 by Thudo

Share this post


Link to post
Share on other sites
PsaltyDS

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

:idea:

Edit: Typo

Edited 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

Share this post


Link to post
Share on other sites
zorphnog

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.

Share this post


Link to post
Share on other sites
Thudo

Yeah sorry it works perfectly and have it doing its magic. Thanks AutoIT staff and community for your patience :idea:

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 by Thudo

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.