コード例 #1
0
 /// <summary>
 /// C-tor. If autoCreateEmptyDirectory is true and the path does not exist then a new empty directory will be (recursevly) created.
 /// </summary>
 /// <param name="fileSystem">The file system to use. Must not be null.</param>
 /// <param name="path">The path the object is based on. Must not be null.</param>
 /// <param name="autoCreateEmptyDirectory">If true and the path does not exist then a new empty directory will be (recursevly) created</param>
 /// <exception cref="FileSystemPathDoesNotExistException">Thrown if the path points to a non-existing directory and autoCreateEmptyDirectory is false.</exception>
 /// <exception cref="DirectoryExpectedException">In case the path points to a non-directory file system entity.</exception>
 public DirectoryBasedObject(IFileSystem fileSystem, FileSystemPath path, bool autoCreateEmptyDirectory)
     : base(fileSystem, path)
 {
     if (autoCreateEmptyDirectory)
     {
         fileSystem.EnsureDirectory(path);
     }
     else
     {
         fileSystem.AssertDirectory(path);
     }
 }
コード例 #2
0
 /// <summary>
 /// Ensures that the path to the directory exists. If it doesn't the directories will be created recursevly. If
 /// the path points to a directory, nothing will happen. If it points to a different object, an exception is
 /// thrown.
 /// </summary>
 /// <param name="this">The extended object</param>
 /// <param name="path">The path to the directory to create.</param>
 /// <returns>True if there was a need to create the directories</returns>
 /// <exception cref="DirectoryExpectedException">Thrown if the path points to a directory.</exception>
 public static bool EnsureDirectory(this IFileSystem @this, FileSystemPath path)
 {
     if (@this.Exists(path))
     {
         @this.AssertDirectory(path);
         return(false);
     }
     else
     {
         @this.CreateDirectoryRecursively(path);
         return(true);
     }
 }