// // Copyright (c) 2008-2011, Kenneth Bell // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System.IO; using DiscUtils.Internal; namespace DiscUtils { /// /// Provides information about a directory on a disc. /// /// /// This class allows navigation of the disc directory/file hierarchy. /// public sealed class DiscDirectoryInfo : DiscFileSystemInfo { /// /// Initializes a new instance of the DiscDirectoryInfo class. /// /// The file system the directory info relates to. /// The path within the file system of the directory. internal DiscDirectoryInfo(DiscFileSystem fileSystem, string path) : base(fileSystem, path) {} /// /// Gets a value indicating whether the directory exists. /// public override bool Exists { get { return FileSystem.DirectoryExists(Path); } } /// /// Gets the full path of the directory. /// public override string FullName { get { return base.FullName + @"\"; } } /// /// Creates a directory. /// public void Create() { FileSystem.CreateDirectory(Path); } /// /// Deletes a directory, even if it's not empty. /// public override void Delete() { FileSystem.DeleteDirectory(Path, false); } /// /// Deletes a directory, with the caller choosing whether to recurse. /// /// true to delete all child node, false to fail if the directory is not empty. public void Delete(bool recursive) { FileSystem.DeleteDirectory(Path, recursive); } /// /// Moves a directory and it's contents to a new path. /// /// The destination directory name. public void MoveTo(string destinationDirName) { FileSystem.MoveDirectory(Path, destinationDirName); } /// /// Gets all child directories. /// /// An array of child directories. public DiscDirectoryInfo[] GetDirectories() { return Utilities.Map(FileSystem.GetDirectories(Path), p => new DiscDirectoryInfo(FileSystem, p)); } /// /// Gets all child directories matching a search pattern. /// /// The search pattern. /// An array of child directories, or empty if none match. /// The search pattern can include the wildcards * (matching 0 or more characters) /// and ? (matching 1 character). public DiscDirectoryInfo[] GetDirectories(string pattern) { return GetDirectories(pattern, SearchOption.TopDirectoryOnly); } /// /// Gets all descendant directories matching a search pattern. /// /// The search pattern. /// Whether to search just this directory, or all children. /// An array of descendant directories, or empty if none match. /// The search pattern can include the wildcards * (matching 0 or more characters) /// and ? (matching 1 character). The option parameter determines whether only immediate /// children, or all children are returned. public DiscDirectoryInfo[] GetDirectories(string pattern, SearchOption searchOption) { return Utilities.Map(FileSystem.GetDirectories(Path, pattern, searchOption), p => new DiscDirectoryInfo(FileSystem, p)); } /// /// Gets all files. /// /// An array of files. public DiscFileInfo[] GetFiles() { return Utilities.Map(FileSystem.GetFiles(Path), p => new DiscFileInfo(FileSystem, p)); } /// /// Gets all files matching a search pattern. /// /// The search pattern. /// An array of files, or empty if none match. /// The search pattern can include the wildcards * (matching 0 or more characters) /// and ? (matching 1 character). public DiscFileInfo[] GetFiles(string pattern) { return GetFiles(pattern, SearchOption.TopDirectoryOnly); } /// /// Gets all descendant files matching a search pattern. /// /// The search pattern. /// Whether to search just this directory, or all children. /// An array of descendant files, or empty if none match. /// The search pattern can include the wildcards * (matching 0 or more characters) /// and ? (matching 1 character). The option parameter determines whether only immediate /// children, or all children are returned. public DiscFileInfo[] GetFiles(string pattern, SearchOption searchOption) { return Utilities.Map(FileSystem.GetFiles(Path, pattern, searchOption), p => new DiscFileInfo(FileSystem, p)); } /// /// Gets all files and directories in this directory. /// /// An array of files and directories. public DiscFileSystemInfo[] GetFileSystemInfos() { return Utilities.Map(FileSystem.GetFileSystemEntries(Path), p => new DiscFileSystemInfo(FileSystem, p)); } /// /// Gets all files and directories in this directory. /// /// The search pattern. /// An array of files and directories. /// The search pattern can include the wildcards * (matching 0 or more characters) /// and ? (matching 1 character). public DiscFileSystemInfo[] GetFileSystemInfos(string pattern) { return Utilities.Map(FileSystem.GetFileSystemEntries(Path, pattern), p => new DiscFileSystemInfo(FileSystem, p)); } } }