Class filesystem
File and directory functions. Copy, move, delete, find, get properties, enumerate, create directory, load/save, etc.
public static class filesystem
Remarks
Also you can use .NET file system classes, such as System.IO.File and System.IO.Directory in System.IO namespace. In the past they were too limited and unsafe to use, for example no long paths, too many exceptions, difficult to recursively enumerate directories containing protected items. Later improved, but this class still has something they don't, for example environment variables in path, safe load/save. This class does not have low-level functions to open/read/write files.
Most functions support only full path. Most of them throw ArgumentException if passed a filename or relative path, ie in "current directory". Using current directory is unsafe.
Most functions support extended-length paths (longer than 259). Such local paths should have @"\\?\"
prefix, like @"\\?\C:\..."
. Such network path should be like @"\\?\UNC\server\share\..."
. See pathname.prefixLongPath, pathname.prefixLongPathIfNeed. Many functions support long paths even without prefix.
Disk drives like @"C:\"
or "C:"
are directories too.
Namespace: Au
Assembly: Au.dll
Methods
Name | Description |
---|---|
copy(string, string, FIfExists, FCFlags, Func<FEFile, bool>, Func<FEFile, int>) | Copies file or directory. |
copyTo(string, string, FIfExists, FCFlags, Func<FEFile, bool>, Func<FEFile, int>) | Copies file or directory into another directory. |
createDirectory(string, string) | Creates new directory if does not exists. If need, creates missing parent/ancestor directories. |
createDirectoryFor(string) | Creates parent directory for a new file, if does not exist. The same as filesystem.createDirectory, just removes filename from filePath. |
delete(IEnumerable<string>, FDFlags) | Deletes multiple files or/and directories. |
delete(string, FDFlags) | Deletes file or directory if exists. |
enumDirectories(string, string, FEFlags) | Gets names and other info of matching subdirectories in the specified directory. |
enumFiles(string, string, FEFlags) | Gets names and other info of matching files in the specified directory. |
enumerate(string, FEFlags, Func<FEFile, bool>, Func<FEFile, int>, Action<string>) | Gets names and other info of files and subdirectories in the specified directory. |
exists(string, bool) | Gets file or directory attributes as FAttr that tells whether it exists, is directory, readonly, hidden, system, NTFS link. See examples. |
getAttributes(string, out FileAttributes, FAFlags) | Gets file or directory attributes. |
getProperties(string, out FileProperties, FAFlags) | Gets file or directory attributes, size and times. Calls API GetFileAttributesEx. |
loadBytes(string, int, int) | Loads file in a safer way. Uses System.IO.File.ReadAllBytes and filesystem.waitIfLocked<T>. |
loadStream(string, int, int) | Loads file in a safer way. Uses System.IO.File.OpenRead and filesystem.waitIfLocked<T>. |
loadText(string, Encoding, int, int) | Loads text file in a safer way. Uses System.IO.File.ReadAllText and filesystem.waitIfLocked<T>. |
move(string, string, FIfExists) | Moves (changes path of) file or directory. |
moveTo(string, string, FIfExists) | Moves file or directory into another directory. |
rename(string, string, FIfExists) | Renames file or directory. |
save(string, Action<string>, bool, string, int) | Writes any data to a file in a safe way, using a callback function. |
saveBytes(string, byte[], bool, string, int) | Writes data to a file in a safe way (like filesystem.save), using System.IO.File.WriteAllBytes. |
saveText(string, string, bool, string, int, Encoding) | Writes text to a file in a safe way (like filesystem.save), using System.IO.File.WriteAllText. |
searchPath(string, params string[]) | Finds file or directory and returns full path. |
setAttributes(string, FileAttributes, bool?, FAFlags) | Sets file or directory attributes. |
waitIfLocked(Action, int) | This function can be used to safely open a file that may be temporarily locked (used by another process or thread). Waits while the file is locked. |
waitIfLocked<T>(Func<T>, int) | This function can be used to safely open a file that may be temporarily locked (used by another process or thread). Waits while the file is locked. |