/// <summary>
 /// Gets a <see cref="ReadOnlyDirectoryEntry"/> for the specified path. If the file does not exist, throws a <see cref="DirectoryNotFoundException"/>
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="directoryPath">The directory path.</param>
 /// <returns>A new <see cref="ReadOnlyDirectoryEntry"/> from the specified path.</returns>
 public static ReadOnlyDirectoryEntry GetDirectoryEntry(this IReadOnlyFileSystem fileSystem, UPath directoryPath)
 {
     if (!fileSystem.DirectoryExists(directoryPath))
     {
         throw FileSystemExceptionHelper.NewDirectoryNotFoundException(directoryPath);
     }
     return(new ReadOnlyDirectoryEntry(fileSystem, directoryPath));
 }
 /// <summary>
 /// Returns an enumerable collection of <see cref="ReadOnlyFileSystemEntry"/> that match a search pattern in a specified path.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="path">The path of the directory to look for files and directories.</param>
 /// <param name="searchPattern">The search string to match against the names of directories in path. This parameter can contain a combination
 /// of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.</param>
 /// <param name="searchOption">One of the enumeration values that specifies whether the search operation should include only the current directory
 /// or should include all subdirectories.
 /// The default value is TopDirectoryOnly.</param>
 /// <param name="searchTarget">The search target either <see cref="SearchTarget.Both"/> or only <see cref="SearchTarget.Directory"/> or <see cref="SearchTarget.File"/>. Default is <see cref="SearchTarget.Both"/></param>
 /// <returns>An enumerable collection of <see cref="ReadOnlyFileSystemEntry"/> that match a search pattern in a specified path.</returns>
 public static IEnumerable <ReadOnlyFileSystemEntry> EnumerateFileSystemEntries(this IReadOnlyFileSystem fileSystem, UPath path, string searchPattern, SearchOption searchOption, SearchTarget searchTarget = SearchTarget.Both)
 {
     if (searchPattern == null)
     {
         throw new ArgumentNullException(nameof(searchPattern));
     }
     foreach (var subPath in fileSystem.EnumeratePaths(path, searchPattern, searchOption, searchTarget))
     {
         yield return(fileSystem.DirectoryExists(subPath) ? (ReadOnlyFileSystemEntry) new ReadOnlyDirectoryEntry(fileSystem, subPath) : new ReadOnlyFileEntry(fileSystem, subPath));
     }
 }
        /// <summary>
        /// Tries to get a <see cref="ReadOnlyFileSystemEntry"/> for the specified path. If the file or directory does not exist, returns null.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="path">The file or directory path.</param>
        /// <returns>A new <see cref="ReadOnlyFileSystemEntry"/> from the specified path.</returns>
        public static ReadOnlyFileSystemEntry TryGetFileSystemEntry(this IReadOnlyFileSystem fileSystem, UPath path)
        {
            var fileExists = fileSystem.FileExists(path);

            if (fileExists)
            {
                return(new ReadOnlyFileEntry(fileSystem, path));
            }
            var directoryExists = fileSystem.DirectoryExists(path);

            return(directoryExists ? new ReadOnlyDirectoryEntry(fileSystem, path) : null);
        }
        /// <summary>
        /// Gets a <see cref="ReadOnlyFileSystemEntry"/> for the specified path. If the file or directory does not exist, throws a <see cref="FileNotFoundException"/>
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="path">The file or directory path.</param>
        /// <returns>A new <see cref="ReadOnlyFileSystemEntry"/> from the specified path.</returns>
        public static ReadOnlyFileSystemEntry GetFileSystemEntry(this IReadOnlyFileSystem fileSystem, UPath path)
        {
            var fileExists = fileSystem.FileExists(path);

            if (fileExists)
            {
                return(new ReadOnlyFileEntry(fileSystem, path));
            }
            var directoryExists = fileSystem.DirectoryExists(path);

            if (directoryExists)
            {
                return(new ReadOnlyDirectoryEntry(fileSystem, path));
            }

            throw FileSystemExceptionHelper.NewFileNotFoundException(path);
        }
 public bool DirectoryExists(DirectoryName path)
 {
     return(fileSystem.DirectoryExists(basePath.Combine(path)));
 }