/// <summary> /// Gets a <see cref="ReadOnlyFileEntry"/> for the specified path. If the file does not exist, throws a <see cref="FileNotFoundException"/> /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="filePath">The file path.</param> /// <returns>A new <see cref="ReadOnlyFileEntry"/> from the specified path.</returns> public static ReadOnlyFileEntry GetFileEntry(this IReadOnlyFileSystem fileSystem, UPath filePath) { if (!fileSystem.FileExists(filePath)) { throw FileSystemExceptionHelper.NewFileNotFoundException(filePath); } return(new ReadOnlyFileEntry(fileSystem, filePath)); }
/// <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> /// 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); }