public static void DeleteFiles(TreeView treeView, int recentFiles) { //todo: \\roms not working DateTime dt = DateTime.Now; StatusStripControl.InitStatusStrip(string.Empty, fileList.Count); dirList.Sort(); var deletedFiles = 0; foreach (var dir in dirList) { var parentNode = treeView.SafeInvoke(c => c.Nodes.Find(dir, true)); if (parentNode == null) { continue; } var dic = new Dictionary <string, int>(); var myDir = new DirectoryInfo(dir); var list = myDir.GetFiles(UI.GetSearchPattern(), SearchOption.TopDirectoryOnly); var query = list.OrderByDescending(file => file.CreationTime); var i = 0; foreach (var file in query) { i++; var pureName = file.Name.Replace(file.Extension, string.Empty); if (!dic.ContainsKey(pureName)) { dic.Add(pureName, 1); continue; } if (dic[pureName]++ >= recentFiles) { var result = parentNode.OfType <TreeNode>() .FirstOrDefault(node => node.Text.Equals(file.Name)); treeView.SafeInvoke(c => c.Nodes.Remove(result)); fileList.Remove(file.FullName); file.Delete(); deletedFiles++; } } StatusStripControl.UpdateProgressBar(); StatusStripControl.UpdateLabel($"{i++}/{foundDir} - {dir}"); } StatusStripControl.UpdateLabel($"{deletedFiles} {UI.GetExtensionName()} files deleted in {DateTime.Now.Subtract(dt).TotalSeconds.ToString("#.#")} seconds"); }
public static void BackupFiles(string selectedNode, string path, string baseInputPath) { DateTime dt = DateTime.Now; StatusStripControl.InitStatusStrip(string.Empty, fileList.Count); //todo: criar caminhos relativos? var i = 1; var newLIst = fileList.ToList(); if (!string.IsNullOrEmpty(selectedNode)) { newLIst.RemoveAll(u => !u.Contains(selectedNode)); } newLIst.Sort(); foreach (var file in newLIst) { StatusStripControl.UpdateProgressBar(); StatusStripControl.UpdateLabel($"{i++}/{found} - {file}"); var fileFolder = FS.GetFolderName(file).Replace(baseInputPath + "\\", ""); fileFolder = FS.PathCombine(path, fileFolder); if (!FS.FolderExists(fileFolder)) { FS.CreateFolder(fileFolder); } FS.CopyFileIfNewer(file, FS.PathCombine(path, fileFolder)); } StatusStripControl.UpdateLabel($"{found} {UI.GetExtensionName()} files backup completed in {DateTime.Now.Subtract(dt).TotalSeconds.ToString("#.#")} seconds"); found = 0; if (string.IsNullOrEmpty(selectedNode)) { fileList.Clear(); } }