/// <summary> /// Finds the appropriate function to paste an item to a new location. /// </summary> /// <param name="fs">Filesystem to use for pasting.</param> /// <param name="source">The source Info.</param> /// <param name="removeSource">Whether to remove the source item after pasting.</param> /// <returns>An action that may be called with the new destination for <paramref name="source"/>.</returns> public static Action <string> GetPasterFor(this IFileSystem fs, FileSystemInfoBase source, bool removeSource) { if (!source.IsDirectory() && removeSource) { return((string dest) => fs.File.Move(source.FullName, dest)); } if (!source.IsDirectory() && !removeSource) { return((string dest) => fs.File.Copy(source.FullName, dest)); } if (source.IsDirectory() && removeSource) { return((string dest) => fs.Directory.Move(source.FullName, dest)); } if (source.IsDirectory() && !removeSource) { return((string dest) => Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(source.FullName, dest)); } throw new ArgumentException($"Could not paste '{source.Name}"); }
/// <summary> /// Gets the MIME type of a filesystem object based on its type and extension. /// </summary> /// <param name="fsinfo">The entity to type.</param> /// <returns>The entity's MIME type.</returns> public static string GetMimeType(this FileSystemInfoBase fsinfo) { return(fsinfo.IsDirectory() ? "inode/directory" : MimeMapping.GetMimeMapping(fsinfo.Name)); }