findFirstFile

Syntax

int findFirstFile(char* lpFileName, char* foundItem, int *dwFileAttributes)

Arguments

lpFileName
The path to the directory to start looking for files. This can be appended with a wildcard to search for specific files.
foundItem
A string where the name of the found file will be stored.
dwFileAttributes
An integer where the attributes of the located file will be stored (see below for attributes list).

File Attributes

FILE_ATTRIBUTE_ARCHIVE A file or directory that is an archive file or directory.
FILE_ATTRIBUTE_COMPRESSED A file or directory that is compressed.
FILE_ATTRIBUTE_DEVICE This value is reserved for system use.
FILE_ATTRIBUTE_DIRECTORY The handle that identifies a directory.
FILE_ATTRIBUTE_ENCRYPTED A file or directory that is encrypted.
FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing.
FILE_ATTRIBUTE_INTEGRITY_STREAM The directory or user data stream is configured with integrity (only supported on ReFS volumes).
FILE_ATTRIBUTE_NORMAL A file that does not have other attributes set. This attribute is valid only when used alone.
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED The file or directory is not to be indexed by the content indexing service.
FILE_ATTRIBUTE_NO_SCRUB_DATA The user data stream not to be read by the background data integrity scanner (AKA scrubber).
FILE_ATTRIBUTE_OFFLINE The file data is physically moved to offline storage.
FILE_ATTRIBUTE_READONLY A file that is read-only.
FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS The file or directory is not fully present locally. For a file that means that not all of its data is on local storage (e.g. it may be sparse with some data still in remote storage).
FILE_ATTRIBUTE_RECALL_ON_OPEN The file or directory has no physical representation on the local system; the item is virtual.
FILE_ATTRIBUTE_REPARSE_POINT A file that is a symbolic link.
FILE_ATTRIBUTE_SPARSE_FILE A file that is a sparse file.
FILE_ATTRIBUTE_SYSTEM A file or directory that the operating system uses a part of, or uses exclusively.
FILE_ATTRIBUTE_TEMPORARY A file that is being used for temporary storage.
FILE_ATTRIBUTE_VIRTUAL This value is reserved for system use.

Return

Returns INVALID_HANDLE_VALUE if the search failed or could not find any files. Otherwise it returns a search handle that can be used in subsequent calls to findNextFile or findClose.

Description

Searches a directory for a file or subdirectory matching the given name or wildcard.

Example

%ffp

OnFilterStart: {

  int Handle, Attribute;

  // Search for 8bf files in the filterInstallDir
  snprintf(str1, 255, "%s\\*.8bf", filterInstallDir);	

  // Optionally, search the C: root instead
  //strcpy(str1,"C:\\");

  Handle = findFirstFile (str1, str9, &Attribute);
  if (Attribute != FILE_ATTRIBUTE_DIRECTORY) 
    Info ("%s - %d",str9, Attribute);
     
  if (Handle != INVALID_HANDLE_VALUE){
    while (findNextFile(Handle, str9, &Attribute) != 0) { 
      if (Attribute != FILE_ATTRIBUTE_DIRECTORY) 
        Info ("%s - %d",str9, Attribute);
    }
  }

  findClose(Handle);

  return false;
}

See Also

findNextFile, findClose