Finds a file whose name matches the sFileSpec. File Status is also returned optionally for v51 only.
[ lAttrib = ] FileFind ( sFileSpec, pbsFileName, [pstFileStatus] )
The FileFind procedure syntax has the following parts:
Name |
Type |
Description |
lAttrib |
Long |
Found file attributes |
sFileSpec |
Val BString |
File specification |
pbsFileName |
Var BString |
Found file name |
pstFileStatus |
Var structFileStatus |
Found File's status Information - v5.1 only |
The sFileSpec is a string expression that specifies a path or a filename. The path and filename can include a drive specification and any valid wild card characters (? and *) and can be specified as absolute, relative or UNC file paths.
By default the filename is limited to 260 characters. To extend the filename to 32,767 characters, the sFileSpec must be specified as follows:
● Absolute file path - prefix the string with "\\\\?\\". For example "\\\\?\\C:\\foldername\\*.txt"
● UNC file path -prefix the string with "\\\\?\\UNC\\". For example "\\\\?\\UNC\\computername\\sharedname\\folder\\*.txt".
● All other file path format relative or partial path (For example "..\\*.txt") - the limit for 260 characters still applies.
The sFileName must be large enough to contain the found file name (when using fixed string).
The function returns the first filename that matches sFileSpec. Additional filenames that match the sFileSpec pattern can be retrieved by calling FileFind again with sFileSpec as an empty string.
When no filenames match, FileFind returns a null string and iAttrib is 0. Once FileFind has returned a null string, the sFileSpec argument must be used again in subsequent calls or the function returns 0.
Internally, FileFind will uses Windows API that create a handle/lock to the path specified, to release the handle you must call the FileFind again until 0 is retuned.
Not all sFileNames that match the given sFileName must be retrieved before calling FileFind again with a new sFileSpec.
FileFind is not case sensitive. "C" is equivalent to "c."
The return value lAttrib specifies the attributes of the found file name. The following list specifies the possible values:
0x00 |
File Not Found |
0x01 |
Read Only |
0x02 |
Hidden |
0x04 |
System |
0x08 |
Volume ID |
0x10 |
Directory |
0x20 |
Archive |
0x80 |
Normal |
The lAttrib can be a combination of these values.
The following example displays all files with prefix "~~" and with the "txt" extension in the root directory:
lAttrib=FileFind("\\~~*.txt", bsFileName)
while lAttrib and Right(bsFileName, 7) <> "~~a.txt" do
lAttrib=FileFind("", bsFileName)
endwhile
if Right(bsFileName, 7) <> "~~a.txt"
TestStatus=FAIL
endif
The following example shows the use of third optional parameter:
lAttrib = FileFind(sPath+"\\*.*", sFile, stStatus)
while lAttrib
if lAttrib=0x20
! Add Item to Main Column and all sub columns
obItem=lvwLogFiles.ListItems.Add(,,sFile,,) !
for i=0 to iSubColCount-1
sDate=FormatDateTime(stStatus.dtLastModified, "%m/%d/%Y %I:%M %p")
obItem.SubItems(i+1)=sDate
next
iIndex=iIndex+1
endif
lAttrib=FileFind("", sFile, stStatus)
endwhile