private IEnumerable <FsChild <FsFile> > GetFiles(string path) { IEnumerable <FsFolder> folders = new [] { path.ToFolder() }; if (Recursive) { folders = folders.Union(GetFolders(path).Select(x => x.Child)); } foreach (var folder in folders) { var files = Directory.EnumerateFiles(folder, "*", SearchOption.TopDirectoryOnly); foreach (var file in files) { var subpath = new Child <FsFile>(this, new File(file)); if (!FilesFilter?.IsMatch(subpath.SubPath) ?? false) { continue; } if (FilesSkip?.IsMatch(subpath.SubPath) ?? false) { continue; } yield return(subpath); } } }
private void DirectoryCopy(string sourceDirName, string destDirName) { // Get the subdirectories for the specified directory. DirectoryInfo dir = new DirectoryInfo(sourceDirName); if (!dir.Exists) { throw new DirectoryNotFoundException("Mr Meeseeks cannot do impossible: source directory does not exist or could not be found: " + sourceDirName); } DirectoryInfo[] dirs = dir.GetDirectories(); // If the destination directory doesn't exist, create it. if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } // Get the files in the directory and copy them to the new location. FileInfo[] files = dir.GetFiles(); files = FilesFilter.Filter(files, IncludedTypes, IncludedRegex, ExcludedTypes, ExcludedRegex); foreach (FileInfo file in files) { string temppath = Path.Combine(destDirName, file.Name); file.CopyTo(temppath, ReplaceIfExists); } // If copying subdirectories, copy them and their contents to new location. if (Recursive) { foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(destDirName, subdir.Name); DirectoryCopy(subdir.FullName, temppath); // Here we should delete empty trees. } } }