Sign in to follow this  
Followers 0
Ephesian

FileFindFirstFile Question

5 posts in this topic

Quick question, no specific coding question, just curious to know what the difference is between FileFindFirstFile returning a -1 and setting the @error to 1. The help file seemed sort of vague whaen they state "Failure: Returns -1 if error occurs", what other kind of error could there be other than an empty directory? It seems to Return -1 when there are no files in the folder, but it also sets @error to 1. So what other errors (if any) would Return -1. Seems sort of redundant. Just curious.

Share this post


Link to post
Share on other sites



True this and I believe you will understand.

DirCreate(@MyDocumentsDir & '\Empty Folder') ;Create a new empty folder
$hFound = FileFindFirstFile(@MyDocumentsDir & '\Empty Folder\*.*')
MsgBox(0,'Empty folder results','@error = ' & @error & @CRLF & '$hFound= ' & $hFound & @CRLF)
DirRemove(@MyDocumentsDir & '\Empty Folder') ;Delete the dir just made

$hFound = FileFindFirstFile(@MyDocumentsDir & '\Not A Real Filename.*')
MsgBox(0,'No matchinf file results','@error = ' & @error & @CRLF & '$hFound= ' & $hFound & @CRLF)

Share this post


Link to post
Share on other sites

There are other error conditions possible, like USB disk unexpected removal in the middle of the loop, access rights being suddenly changed (not sure there), you name it.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

FileFindFirstFile used to return "." and ".." within folders until they were removed as considered unnecessary at the time, or so it was thought. But some used those directory dots to know whether they were in a folder or the root of the drive. The @error condition was later added as a means to know whether FileFindFirstFile is searching an empty folder or not. If you do get the return of -1 and you do not get @error set then your probably in the root of an empty drive.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Awesome, thanks for the info. It was helpful!

Edited by Ephesian

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