void CopyDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir) { FileInfoEx[] files = srcDir.GetFiles(); AddTotalCount(files.Length); foreach (FileInfoEx fi in files) if (!Aborted) { CheckPause(); AddCompletedCount(fi.FullName); CopyFile(fi, destDir); } files = null; DirectoryInfoEx[] dirs = srcDir.GetDirectories(); AddTotalCount(dirs.Length); foreach (DirectoryInfoEx di in dirs) if (!Aborted) { CheckPause(); AddCompletedCount(di.FullName); DirectoryInfoEx destSubDir = PrepateDirectoryForCopy(di, destDir, di.Name); if (destSubDir != null) CopyDirectory(di, destSubDir); } dirs = null; }
void CopyDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir) { FileInfoEx[] files = srcDir.GetFiles(); AddTotalCount(files.Length); foreach (FileInfoEx fi in files) { if (!Aborted) { CheckPause(); AddCompletedCount(fi.FullName); CopyFile(fi, destDir); } } files = null; DirectoryInfoEx[] dirs = srcDir.GetDirectories(); AddTotalCount(dirs.Length); foreach (DirectoryInfoEx di in dirs) { if (!Aborted) { CheckPause(); AddCompletedCount(di.FullName); DirectoryInfoEx destSubDir = PrepateDirectoryForCopy(di, destDir, di.Name); if (destSubDir != null) { CopyDirectory(di, destSubDir); } } } dirs = null; }
void MoveDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir) { FileInfoEx[] files = srcDir.GetFiles(); AddTotalCount(files.Length); foreach (FileInfoEx fi in files) if (!Aborted) { CheckPause(); AddCompletedCount(fi.FullName); MoveFile(fi, destDir); } files = null; DirectoryInfoEx[] dirs = srcDir.GetDirectories(); AddTotalCount(dirs.Length); foreach (DirectoryInfoEx di in dirs) if (!Aborted) { CheckPause(); AddCompletedCount(di.FullName); DirectoryInfoEx destSubDir = PrepateDirectoryForMove(di, destDir, di.Name); if (destSubDir != null) MoveDirectory(di, destSubDir); } dirs = null; if (srcDir.Exists && srcDir.GetFileSystemInfos().Length == 0) srcDir.Delete(); }
private void ListDir(DirectoryInfoEx dir) { foreach (FileInfoEx fi in dir.GetFiles()) if (_listFile && (String.IsNullOrEmpty(_fileMask) || IOTools.MatchFileMask(fi.Name, _fileMask))) ReportWorkList(fi); DirectoryInfoEx[] dirs = dir.GetDirectories(); AddTotalCount(dirs.Length); foreach (DirectoryInfoEx di in dirs) { if (_listDir) ReportWorkList(di); ListDir(di); AddCompletedCount(di.FullName); } dirs = null; }
public void CopyAllFix(string sourcePath, string destinationPath) { var directories = DirectoryInfoEx.GetDirectories(sourcePath, "*.*", SearchOption.AllDirectories); foreach (var srcDirPath in directories) { string tempDestPath = Uri.UnescapeDataString(srcDirPath.FullName.Replace(sourcePath, destinationPath, StringComparison.OrdinalIgnoreCase)); if (DirectoryInfoEx.CreateDirectory(tempDestPath, out string errorMessage) != 0) { ErrorLog.Inst.LogError(errorMessage); } } var files = DirectoryInfoEx.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories); foreach (var srcFilePath in files) { string tempDestPath = Uri.UnescapeDataString(srcFilePath.FullName.Replace(sourcePath, destinationPath, StringComparison.OrdinalIgnoreCase)); File.Copy(srcFilePath.FullName, tempDestPath, true); } }
public static IEnumerable <FileInfoEx> EnumerateFilesEx(this DirectoryInfoEx path) { var queue = new Queue <DirectoryInfoEx>(); queue.Enqueue(path); IEnumerable <FileSystemInfoEx> tmp; while (queue.Count > 0) { path = queue.Dequeue(); try { tmp = path.GetFiles(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); continue; } foreach (var t in tmp) { yield return(t as FileInfoEx); } try { tmp = path.GetDirectories(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); continue; } foreach (var subDir in tmp) { queue.Enqueue(subDir as DirectoryInfoEx); } } }
protected TreeNode CreateDirectoryNode(DirectoryInfoEx directoryInfo) { var directoryNode = new TreeNode(directoryInfo.Name); foreach (var directory in directoryInfo.GetDirectories()) { var nodeItem = CreateDirectoryNode(directory); var folderInfo = new FolderInfo(directory.FullName); folderInfo.CanDelete = true; nodeItem.Tag = folderInfo; directoryNode.Nodes.Add(nodeItem); } foreach (var file in directoryInfo.GetFiles()) { var nodeItem = new TreeNode(file.Name); var fileInfo = new FileInfo(file.FullName); fileInfo.CanDelete = true; nodeItem.Tag = fileInfo; directoryNode.Nodes.Add(nodeItem); } return(directoryNode); }
public static async Task <bool> AddFolder(DirectoryInfoEx dir, bool subfolders, Action <Exception, string> errorCallback) { var arr = Task.Run(() => { IEnumerable <IMusicInfo> stuff; if (subfolders) { stuff = from f in dir.EnumerateFilesEx() where PlaybackManager.Instance.HasSupportingPlayer(f.Name.GetExt()) select MusicInfo.Create(f, errorCallback); } else { stuff = from f in dir.GetFiles() where PlaybackManager.Instance.HasSupportingPlayer(f.Name.GetExt()) select MusicInfo.Create(f, errorCallback); } return(stuff.ToArray()); }); PlaybackManager.Instance.Playlist.AddRange(await arr); return(true); }
void MoveDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir) { FileInfoEx[] files = srcDir.GetFiles(); AddTotalCount(files.Length); foreach (FileInfoEx fi in files) { if (!Aborted) { CheckPause(); AddCompletedCount(fi.FullName); MoveFile(fi, destDir); } } files = null; DirectoryInfoEx[] dirs = srcDir.GetDirectories(); AddTotalCount(dirs.Length); foreach (DirectoryInfoEx di in dirs) { if (!Aborted) { CheckPause(); AddCompletedCount(di.FullName); DirectoryInfoEx destSubDir = PrepateDirectoryForMove(di, destDir, di.Name); if (destSubDir != null) { MoveDirectory(di, destSubDir); } } } dirs = null; if (srcDir.Exists && srcDir.GetFileSystemInfos().Length == 0) { srcDir.Delete(); } }
private void ListDir(DirectoryInfoEx dir) { foreach (FileInfoEx fi in dir.GetFiles()) { if (_listFile && (String.IsNullOrEmpty(_fileMask) || IOTools.MatchFileMask(fi.Name, _fileMask))) { ReportWorkList(fi); } } DirectoryInfoEx[] dirs = dir.GetDirectories(); AddTotalCount(dirs.Length); foreach (DirectoryInfoEx di in dirs) { if (_listDir) { ReportWorkList(di); } ListDir(di); AddCompletedCount(di.FullName); } dirs = null; }