public static IList <FileSignature> CreateSignatures( FsPath path, string pattern = "*", Dictionary <FsPath, FileSignature> precalculated = null) { var files = path.EnumerateFiles(pattern, SearchOption.AllDirectories); var result = new List <FileSignature>(); using var md5 = MD5.Create(); foreach (FsPath file in files) { if (Str.Equals(file.Basename(), SignaturesFile.Value)) { continue; } var relativePath = file.RelativeTo(path); if (precalculated == null || !precalculated.TryGetValue(relativePath, out var signature)) { signature = new FileSignature { Path = relativePath, Md5Hash = getMd5Hash(md5, file.ReadAllBytes()) }; } result.Add(signature); } return(result); }
public static void CopyDirectoryTo(this FsPath path, FsPath other, bool overwrite) { foreach (FsPath dirPath in path.EnumerateDirectories("*", SearchOption.AllDirectories).ToArray()) { dirPath.ChangeDirectory(path, other).CreateDirectory(); } foreach (FsPath newPath in path.EnumerateFiles("*", SearchOption.AllDirectories)) { newPath.CopyFileTo(newPath.ChangeDirectory(path, other), overwrite); } }
public static void EnsureEmptyDirectory(this FsPath path) { if (!path.IsDirectory()) { path.CreateDirectory(); return; } foreach (var subdirInfo in path.EnumerateDirectories().ToArray()) { subdirInfo.DeleteDirectory(recursive: true); } foreach (var fileInfo in path.EnumerateFiles().ToArray()) { fileInfo.DeleteFile(); } }