Method filesystem.enumerate
Overload
Gets names and other info of files and subdirectories in the specified directory.
public static IEnumerable<FEFile> enumerate(string directoryPath, FEFlags flags = 0, Func<FEFile, bool> fileFilter = null, Func<FEFile, int> dirFilter = null, Action<string> errorHandler = null)
Parameters
directoryPath (string)
Full path of the directory. |
flags (FEFlags) |
fileFilter (Func<FEFile, bool>)
Callback function that is called for each file (but not subdirectory). Let it return |
dirFilter (Func<FEFile, int>)
Callback function that is called for each subdirectory. Let it return flags: 1 - include the directory in results; 2 - include its children in results.
The return value overrides flags FEFlags.OnlyFiles and FEFlags.AllDescendants.
Example: |
errorHandler (Action<string>)
Callback function that is called when fails to get children of a subdirectory, when using flag FEFlags.AllDescendants. Receives the subdirectory path. Can call lastError.Code and throw an exception. If does not throw, the enumeration continues as if the directory is empty. If errorHandler not used, then enumerate throws exception. See also: flag FEFlags.IgnoreInaccessible. |
Returns
IEnumerable<FEFile>
An enumerable collection of FEFile objects. |
Exceptions
ArgumentException
directoryPath is invalid path or not full path. |
DirectoryNotFoundException
directoryPath directory does not exist. |
AuException
Failed to get children of directoryPath or of a subdirectory. |
Remarks
Uses API FindFirstFile.
By default gets only direct children. Use flag FEFlags.AllDescendants to get all descendants.
The paths that this function gets are normalized, ie may not start with exact directoryPath string. Expanded environment variables (see pathname.expand), ".."
, DOS path etc. Paths longer than pathname.maxDirectoryPathLength have @"\\?\"
prefix (see pathname.prefixLongPathIfNeed).
For NTFS links (symbolic links, mount points) gets link info, not target info.
These errors are ignored:
- Missing target directory of a NTFS link.
- If used flag FEFlags.IgnoreInaccessible - access denied.
When an error is ignored, the function works as if that [sub]directory is empty; does not throw exception and does not call errorHandler.
Enumeration of a subdirectory starts immediately after the subdirectory itself is retrieved.