LocalFileSystem
Implementation of IFileSystem over the local file system (IO).
实现: IFileSystem
属性
public static LocalFileSystem Instance { get; }
value = LocalFileSystem.Instance
Singleton instance (without size limits).
public long MaxSize { get; set; }
value = localFileSystem.MaxSize
localFileSystem.MaxSize = value
Maximum total size of all files in bytes. Zero or negative means unlimited. When set to a positive value, streams are wrapped to track writes.
public FileSystemOverflowBehavior OverflowBehavior { get; set; }
value = localFileSystem.OverflowBehavior
localFileSystem.OverflowBehavior = value
Behavior when MaxSize limit is exceeded.
public long TotalSize { get; }
value = localFileSystem.TotalSize
Current total size tracked for limit enforcement. Only meaningful when MaxSize is positive.
方法
public void CopyFile(string sourceFileName, string destFileName, bool overwrite)
localFileSystem.CopyFile(sourceFileName, destFileName, overwrite)
Copies a file to a new location.
- sourceFileName
- Source file path.
- destFileName
- Destination file path.
- overwrite
- If true, overwrites destination.
public void CreateDirectory(string path)
localFileSystem.CreateDirectory(path)
Creates a directory including all missing intermediate directories.
- path
- Path to the directory.
public void DeleteDirectory(string path, bool recursive)
localFileSystem.DeleteDirectory(path, recursive)
Deletes a directory.
- path
- Path to the directory.
- recursive
- If true, deletes contents recursively.
public void DeleteFile(string path)
localFileSystem.DeleteFile(path)
Deletes a file.
- path
- The path to the file.
public bool DirectoryExists(string path)
result = localFileSystem.DirectoryExists(path)
Checks whether a directory exists at the specified path.
- path
- Path to the directory.
返回值: True if the directory exists; otherwise, false.
public IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)
result = localFileSystem.EnumerateDirectories(path, searchPattern, searchOption)
Enumerates subdirectories in a directory.
- path
- Directory path.
- searchPattern
- Search pattern (supports * and ?).
- searchOption
- Search scope.
返回值: Sequence of directory paths.
public IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption)
result = localFileSystem.EnumerateFiles(path, searchPattern, searchOption)
Enumerates files in a directory.
- path
- Directory path.
- searchPattern
- Search pattern (supports * and ?).
- searchOption
- Search scope.
返回值: Sequence of file paths.
public bool FileExists(string path)
result = localFileSystem.FileExists(path)
Checks whether a file exists at the specified path.
- path
- Path to the file.
返回值: True if the file exists; otherwise, false.
public FileAttributes GetAttributes(string path)
result = localFileSystem.GetAttributes(path)
Gets file or directory attributes (equivalent to File.GetAttributes). Implementations should throw appropriate exceptions if the path does not exist.
- path
- Path to the file or directory.
返回值: The FileAttributes for the given path.
public DateTime GetCreationTimeUtc(string path)
result = localFileSystem.GetCreationTimeUtc(path)
Gets the creation time (UTC) of a file or directory.
- path
- Path.
返回值: Creation time in UTC.
public long GetFileLength(string path)
result = localFileSystem.GetFileLength(path)
Gets file length in bytes.
- path
- Path to the file.
返回值: File size in bytes.
public DateTime GetLastWriteTimeUtc(string path)
result = localFileSystem.GetLastWriteTimeUtc(path)
Gets the last write time (UTC) of a file or directory.
- path
- Path.
返回值: Last write time in UTC.
public void MoveDirectory(string sourceDirName, string destDirName)
localFileSystem.MoveDirectory(sourceDirName, destDirName)
Moves a directory to a new location.
- sourceDirName
- Source directory path.
- destDirName
- Destination directory path.
public void MoveFile(string sourceFileName, string destFileName, bool overwrite)
localFileSystem.MoveFile(sourceFileName, destFileName, overwrite)
Moves a file to a new location.
- sourceFileName
- Source file path.
- destFileName
- Destination file path.
- overwrite
- If true, overwrites destination.
public void SetReadOnly(string path, bool isReadOnly)
localFileSystem.SetReadOnly(path, isReadOnly)
Sets or clears the read-only attribute on the specified file. Implementations should handle cases when the file does not exist gracefully.
- path
- Path to the file.
- isReadOnly
- True to set read-only; false to clear.