/// <summary> /// Opens an existing file at the specified path and returns a <see cref="System.IO.Stream"/> to it. /// </summary> /// <param name="path"></param> /// <param name="mode"></param> public static Stream Open(string path, FileAccessMode mode) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException("The specified path is null or whitespace-only."); } PathOp.CheckInvalidPathChars(path); return(DualityApp.SystemBackend.FileSystem.OpenFile(path, mode)); }
/// <summary> /// Deletes the file that is referred to by the specified path. /// </summary> /// <param name="path"></param> public static void Delete(string path) { if (string.IsNullOrWhiteSpace(path)) { return; } PathOp.CheckInvalidPathChars(path); DualityApp.SystemBackend.FileSystem.DeleteFile(path); }
/// <summary> /// Enumerates all directories that are located within the specified path. /// </summary> /// <param name="path"></param> /// <param name="recursive">If true, the specified path will be searched recursively and yield all descendant directory paths.</param> /// <returns></returns> public static IEnumerable <string> GetDirectories(string path, bool recursive = false) { if (string.IsNullOrWhiteSpace(path)) { return(Enumerable.Empty <string>()); } PathOp.CheckInvalidPathChars(path); return(DualityApp.SystemBackend.FileSystem.GetDirectories(path, recursive)); }
/// <summary> /// Returns whether the specified path refers to an existing file. /// </summary> /// <param name="path"></param> /// <returns></returns> public static bool Exists(string path) { if (string.IsNullOrWhiteSpace(path)) { return(false); } PathOp.CheckInvalidPathChars(path); return(DualityApp.SystemBackend.FileSystem.FileExists(path)); }
/// <summary> /// Creates a directory tree matching the specified directory path. /// </summary> /// <param name="path"></param> public static void Create(string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException("The specified path is null or whitespace-only."); } PathOp.CheckInvalidPathChars(path); DualityApp.SystemBackend.FileSystem.CreateDirectory(path); }
/// <summary> /// Deletes the directory that is referred to by the specified path. /// </summary> /// <param name="path"></param> public static void Delete(string path) { if (string.IsNullOrWhiteSpace(path)) { return; } PathOp.CheckInvalidPathChars(path); PathOp.ResolveFileSystem(ref path).DeleteDirectory(path); }
/// <summary> /// Returns whether the specified path refers to an existing directory. /// </summary> /// <param name="path"></param> /// <returns></returns> public static bool Exists(string path) { if (string.IsNullOrWhiteSpace(path)) { return(false); } PathOp.CheckInvalidPathChars(path); return(PathOp.ResolveFileSystem(ref path).DirectoryExists(path)); }
/// <summary> /// Creates or overwrites a file at the specified path and returns a <see cref="System.IO.Stream"/> to it. /// The returned stream has implicit read / write access. /// </summary> /// <param name="path"></param> public static Stream Create(string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException("The specified path is null or whitespace-only."); } PathOp.CheckInvalidPathChars(path); return(PathOp.ResolveFileSystem(ref path).CreateFile(path)); }
/// <summary> /// Enumerates all directories that are located within the specified path. /// </summary> /// <param name="path"></param> /// <param name="recursive">If true, the specified path will be searched recursively and yield all descendant directory paths.</param> /// <returns></returns> public static IEnumerable <string> GetDirectories(string path, bool recursive = false) { if (string.IsNullOrWhiteSpace(path)) { return(Enumerable.Empty <string>()); } PathOp.CheckInvalidPathChars(path); int index = PathOp.IndexOfFileSystem(path); if (index == -1) { return(DualityApp.SystemBackend.FileSystem.GetDirectories(path, recursive)); } else { return(PathOp.PrepareFileSystemForEnumerationUnsafe(index, true, path, recursive)); } }