Example #1
0
 /// <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));
 }
Example #2
0
 /// <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);
 }
Example #3
0
 /// <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));
 }
Example #4
0
 /// <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));
 }
Example #5
0
 /// <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);
 }
Example #6
0
 /// <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);
 }
Example #7
0
 /// <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));
 }
Example #8
0
 /// <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));
 }
Example #9
0
        /// <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));
            }
        }