public void DeleteSelectedFiles(bool sendToRecycleBin = true) { StringCollection files = GetSelectedFilesStringCollection(); int fileCount = files.Count; RecycleOption recycleOption = sendToRecycleBin ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; UIOption uiOption = fileCount == 1 ? UIOption.AllDialogs : UIOption.OnlyErrorDialogs; if (!sendToRecycleBin && fileCount > 1) { if (MessageBox.Show( String.Format(@"Are you sure that you want to permanently delete these {0} items?", fileCount), @"Delete Multiple Items", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { return; } } foreach (string fileInfo in files) { FileSystem.DeleteFile(fileInfo, uiOption, recycleOption); } RefreshFolder(); }
private async Task DeleteDirectoryIfExistsAsync(string directory, RecycleOption recycleOption) { if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory)) { await DeleteDirectoryAsync(directory, recycleOption); } }
private async Task DeleteAllDirectoriesAsync(string filePath, RecycleOption recycleOption) { foreach (var childPath in Directory.GetDirectories(filePath)) { await DeleteDirectoryAsync(childPath, recycleOption); } }
public static void Cleanup( string path, string searchPattern, string originalDatabasePath, int amountToKeep, RecycleOption recycleOption ) { string[] fileList = Directory.GetFiles(path, searchPattern).OrderByDescending(f => new FileInfo(f).CreationTime).ToArray(); // if more backup files available than required delete the obsolete files if (fileList.Count() > amountToKeep) { for (int i = amountToKeep; i < fileList.Count(); i++) { // never delete original file -> always skip it (in case it made it into the filelist) if (fileList[i].Equals(originalDatabasePath)) { continue; } FileSystem.DeleteFile(fileList[i], UIOption.OnlyErrorDialogs, recycleOption); } } }
public void Clean(bool moveToRecycle) { this._cleanSize = 0; UpdEventArgs args = new UpdEventArgs(); BEncodedDictionary resume = BEncodedValue.Decode <BEncodedDictionary>(File.ReadAllBytes(this._resumePath)); string[] torrentFilesList = Directory.GetFiles(this._torrentsPath, @"*.torrent", System.IO.SearchOption.TopDirectoryOnly); args.MaxProgress = torrentFilesList.Length; args.Progress = 0; args.DeletedCount = 0; this.UpdEvent(this, args); foreach (string file in torrentFilesList) { string fileName = Path.GetFileName(file); if (!resume.ContainsKey(new BEncodedString(fileName))) { RecycleOption ro = RecycleOption.DeletePermanently; if (moveToRecycle) { ro = RecycleOption.SendToRecycleBin; } this._cleanSize += GetFileSize(file); FileSystem.DeleteFile(file, UIOption.OnlyErrorDialogs, ro); args.Msg = strings.DeletingFile.f(fileName); args.CleanSize = this._cleanSize; args.DeletedCount++; } args.Progress++; this.UpdEvent(this, args); } }
// Delete a file or move it to the recycle bin. public static void DeleteFile(string filename, bool confirm, bool delete_permanently) { UIOption ui_option = UIOption.OnlyErrorDialogs; if (confirm) { ui_option = UIOption.AllDialogs; } RecycleOption recycle_option = recycle_option = RecycleOption.SendToRecycleBin; if (delete_permanently) { recycle_option = RecycleOption.DeletePermanently; } try { Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename, ui_option, recycle_option); } catch (Exception ex) { Trace.WriteLine("Error deleting file.\n" + ex.ToString()); } }
//... public static void Recycle(IEnumerable <string> paths, RecycleOption recycleOption = RecycleOption.SendToRecycleBin) { foreach (var i in paths) { Recycle(i, recycleOption); } }
protected override void Cleanup() { string cleanupSearchPattern = dbFileName + "_*" + dbFileExtension; RecycleOption recycleOption = config.UseRecycleBinDeletedBackups ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; CleanupManager.Cleanup(basePath, cleanupSearchPattern, database.IOConnectionInfo.Path, (int)config.FileAmountToKeep, recycleOption); }
private async Task DeleteAllFilesAsync(string filePath, RecycleOption recycleOption) { foreach (var fileName in Directory.GetFiles(filePath)) { var fullPath = Path.Combine(filePath, fileName); await DeleteFileAsync(fullPath, recycleOption); } }
private async Task CleanTemporayFilesAsync(RecycleOption recycleOption) { var filePath = Path.GetTempPath(); if (!string.IsNullOrEmpty(filePath)) { await Task.WhenAll(DeleteAllDirectoriesAsync(filePath, recycleOption), DeleteAllFilesAsync(filePath, recycleOption)); } }
protected override void Cleanup() { string searchPattern = dbFileName + "_*" + dbFileExtension; RecycleOption recycleOption = config.UseRecycleBinDeletedBackups ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; CleanupManager.Cleanup(basePathWeekly, searchPattern, database.IOConnectionInfo.Path, config.LtbWeeklyAmount, recycleOption); CleanupManager.Cleanup(basePathMonthly, searchPattern, database.IOConnectionInfo.Path, config.LtbMonthlyAmount, recycleOption); CleanupManager.Cleanup(basePathYearly, searchPattern, database.IOConnectionInfo.Path, config.LtbYearlyAmount, recycleOption); }
protected override void DoAction() { foreach (FileInfo file in Pwd.EnumerateFiles(ParseStringForVariable(Filename))) { RecycleOption option = SendToRecyclingBin ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; FileSystem.DeleteFile(file.FullName, UIOption.AllDialogs, option); } }
public static void ShellDelete(string FullPath, RecycleOption recycle, UICancelOption OnUserCancel, FileOrDirectory FileOrDirectory) { ShFileOperationFlags operationFlags = ShFileOperationFlags.FOF_SILENT | ShFileOperationFlags.FOF_NOCONFIRMATION; if (recycle == RecycleOption.SendToRecycleBin) { operationFlags |= ShFileOperationFlags.FOF_ALLOWUNDO; } ShellFileOperation(SHFileOperationType.FO_DELETE, operationFlags, FullPath, null, OnUserCancel, FileOrDirectory); }
//public static void DeleteDirectory(String path) //{ // List<DirectoryInfo> folderList = GetFolders(path); // foreach (DirectoryInfo folder in folderList) // { // DeleteDirectory(folder.FullName); // Directory.Delete(folder.FullName); // } // List<FileInfo> fileList = GetFiles(path); // foreach (FileInfo file in fileList) // { // File.Delete(file.FullName); // } //} /// <summary> /// <para>Delete everything in the directory</para> /// <para>Level All</para> /// </summary> public static void DeleteDirectory(String path, RecycleOption recycle = RecycleOption.SendToRecycleBin) { try { FileSystem.DeleteDirectory(path, UIOption.OnlyErrorDialogs, recycle); } catch (Exception e) { ErrorLog.Write(e, MethodBase.GetCurrentMethod().Name); } }
public static void Recycle(string path, RecycleOption recycleOption = RecycleOption.SendToRecycleBin) { try { if (System.IO.Directory.Exists(path)) { Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(path, UIOption.AllDialogs, recycleOption); } else if (System.IO.File.Exists(path)) { Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(path, UIOption.AllDialogs, recycleOption); } } catch { } }
public void DeleteFile(string filepath) { RecycleOption opt = default(RecycleOption); if (CheckBox3.Checked) { opt = RecycleOption.SendToRecycleBin; } else { opt = RecycleOption.DeletePermanently; } FileSystem.DeleteFile(filepath, UIOption.OnlyErrorDialogs, opt); LoadFilesIntoFinder(); H_FILE_LIST.SelectedIndex = CurrentIndex; }
private async Task RemoveCurrentImage() { await Task.Run(() => { VlcPlayer.Stop(); RecycleOption recycleOption = RecycleOption.DeletePermanently; if (SettingsViewModel.SendToRecycleBin) { recycleOption = RecycleOption.SendToRecycleBin; } FileSystem.DeleteFile(_imagePathList[_currentImageIndex].FullName, UIOption.OnlyErrorDialogs, recycleOption); Logging.LogInfo(recycleOption == RecycleOption.DeletePermanently ? "Deleted permanently: " : "Send to recycle bin: " + _imagePathList[_currentImageIndex].FullName); }); }
private async Task CleanAspNetFilesAsync(RecycleOption recycleOption) { var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows, Environment.SpecialFolderOption.None); var localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.None); var tasks = new List <Task>(); var windowsPaths = new[] { windowsFolder + @"\Microsoft.NET\Framework", windowsFolder + @"\Microsoft.NET\Framework64", }; var otherPaths = new[] { localAppDataFolder + @"\Temp\Temporary ASP.NET Files" }; foreach (var filePath in windowsPaths) { if (Directory.Exists(filePath)) { var dotNetDirectories = Directory.GetDirectories(filePath, "v?.*", System.IO.SearchOption.TopDirectoryOnly); foreach (var childPath in dotNetDirectories) { var tempPath = childPath + @"\Temporary ASP.NET Files"; if (Directory.Exists(tempPath)) { tasks.Add(DeleteAllDirectoriesAsync(tempPath, recycleOption)); tasks.Add(DeleteAllFilesAsync(tempPath, recycleOption)); } } } } foreach (var filePath in otherPaths) { if (Directory.Exists(filePath)) { tasks.Add(DeleteAllDirectoriesAsync(filePath, recycleOption)); tasks.Add(DeleteAllFilesAsync(filePath, recycleOption)); } } await Task.WhenAll(tasks); }
private async Task DeleteDirectoryAsync(string filePath, RecycleOption recycleOption) { try { if (Directory.Exists(filePath)) { await Task.Run(() => FileSystem.DeleteDirectory(filePath, UIOption.OnlyErrorDialogs, recycleOption, UICancelOption.DoNothing)); } } catch (IOException ex) // thrown when a folder is in use { _statusTracker.TrackException(filePath, ex); } finally { _statusTracker.Advance(); } }
/// <summary> /// 폴더를 삭제 합니다. /// </summary> /// <param name="path">파일 패스</param> /// <param name="showDialog">삭제확인 표시 문구 표시 여부</param> /// <param name="SendToRecycleBin"></param> /// <returns>작업 취소 여부 true:처리 / false:취소</returns> public static bool DeleteFolder(string path, bool showDialog, bool SendToRecycleBin) { UIOption uiopt = showDialog ? UIOption.AllDialogs : UIOption.OnlyErrorDialogs; RecycleOption rOption = SendToRecycleBin ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; try { FileSystem.DeleteDirectory(path, uiopt, rOption); } catch (OperationCanceledException) { return(false); } catch (Exception ex) { throw ex; } return(true); }
public override void DoWork(IProgress <Tuple <int, string> > progress, CancellationToken token) { for (int i = 0; i < Items.Length; i++) { token.ThrowIfCancellationRequested(); int percentage = i * 100 / Items.Length; progress.Report(new Tuple <int, string>(percentage, Path.GetFileName(Items[i]))); string path = Items[i]; RecycleOption option = Recycle ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; if (Directory.Exists(path)) { FileSystem.DeleteDirectory(path, UIOption.OnlyErrorDialogs, option); } else if (File.Exists(path)) { FileSystem.DeleteFile(path, UIOption.OnlyErrorDialogs, option); } } }
private void DeleteSelection(TreeView treeView) { if (treeView.SelectedNode.Text.Contains(".")) { if (File.Exists(treeView.SelectedNode.Text)) { if (MessageBox.Show("Are You Sure?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) { ResetPreviewWindows(); RecycleOption recycleOption = RecycleOption.SendToRecycleBin; if (!chkBxRecycle.Checked) { recycleOption = RecycleOption.DeletePermanently; } FileSystem.DeleteFile(treeView.SelectedNode.Text, UIOption.OnlyErrorDialogs, recycleOption); RemoveItemFromTree(treeView); UpdateNumberOfNonUniqueHashes(); } } else { // if the file no longer exists on the file system, remove it from the tree view RemoveItemFromTree(treeView); } } else { ResetPreviewWindows(); } }
public void DeleteDirectory(string directory, UIOption showUI, RecycleOption recycle, UICancelOption onUserCancel) { FileSystem.DeleteDirectory(directory, showUI, recycle, onUserCancel); }
public void DeleteDirectory(string directory, UIOption showUI, RecycleOption recycle) { FileSystem.DeleteDirectory(directory, showUI, recycle); }
private static void VerifyRecycleOption(string argName, RecycleOption argValue) { if ((argValue != RecycleOption.DeletePermanently) && (argValue != RecycleOption.SendToRecycleBin)) { throw new InvalidEnumArgumentException(argName, (int) argValue, typeof(RecycleOption)); } }
private async Task CleanRecursiveAsync(string filePath, CleanerOptions options, RecycleOption recycleOption) { var bin = Path.Combine(filePath, "bin"); var obj = Path.Combine(filePath, "obj"); var packages = (options & CleanerOptions.ClearNugetPackages) != CleanerOptions.None ? Path.Combine(filePath, "packages") : string.Empty; var nodeModules = (options & CleanerOptions.ClearNodeModules) != CleanerOptions.None ? Path.Combine(filePath, "node_modules") : string.Empty; var tasks = new List <Task>() { DeleteDirectoryIfExistsAsync(obj, recycleOption), DeleteDirectoryIfExistsAsync(packages, recycleOption), DeleteDirectoryIfExistsAsync(nodeModules, recycleOption) }; // deleting the roslyn folder can cause some weird issues if (Directory.Exists(Path.Combine(bin, "roslyn"))) { tasks.Add(DeleteAllFilesAsync(bin, recycleOption)); } else { tasks.Add(DeleteDirectoryIfExistsAsync(bin, recycleOption)); } await Task.WhenAll(tasks); foreach (var folder in Directory.GetDirectories(filePath)) { // a lot of npm packages have bin & obj folders, so ignore it // also, deleting the roslyn folder can cause issues if (folder.EndsWith("node_modules") || folder.EndsWith("roslyn")) { continue; } await CleanRecursiveAsync(folder, options, recycleOption); } //var tasks = new List<Task>(); //if (!string.IsNullOrEmpty(bin) && Directory.Exists(bin)) tasks.Add(DeleteDirectoryAsync(bin, recycleOption)); //if (!string.IsNullOrEmpty(obj) && Directory.Exists(obj)) tasks.Add(DeleteDirectoryAsync(obj, recycleOption)); //if (!string.IsNullOrEmpty(packages) && Directory.Exists(packages)) tasks.Add(DeleteDirectoryAsync(packages, recycleOption)); //if (!string.IsNullOrEmpty(nodeModules) && Directory.Exists(nodeModules)) tasks.Add(DeleteDirectoryAsync(nodeModules, recycleOption)); //if (tasks.Any()) //{ // await Task.WhenAll(tasks); //} //else //{ // foreach (var folder in Directory.GetDirectories(filePath)) // { // await CleanRecursiveAsync(folder, options, recycleOption); // } //} }
public async Task CleanAsync(string filePath, CleanerOptions options = CleanerOptions.None, RecycleOption recycleOption = RecycleOption.SendToRecycleBin) { var tasks = new List <Task>() { CleanRecursiveAsync(filePath, options, recycleOption) }; if ((options & CleanerOptions.ClearTemporaryFiles) != CleanerOptions.None) { tasks.Add(CleanTemporayFilesAsync(recycleOption)); } if ((options & CleanerOptions.ClearAspNetFiles) != CleanerOptions.None) { tasks.Add(CleanAspNetFilesAsync(recycleOption)); } await Task.WhenAll(tasks); }
private static void DeleteDirectoryInternal(string directory, DeleteDirectoryOption onDirectoryNotEmpty, UIOptionInternal showUI, RecycleOption recycle, UICancelOption onUserCancel) { VerifyDeleteDirectoryOption("onDirectoryNotEmpty", onDirectoryNotEmpty); VerifyRecycleOption("recycle", recycle); VerifyUICancelOption("onUserCancel", onUserCancel); string fullPath = Path.GetFullPath(directory); DemandDirectoryPermission(fullPath, FileIOPermissionAccess.Write); ThrowIfDevicePath(fullPath); if (!Directory.Exists(fullPath)) { throw ExceptionUtils.GetDirectoryNotFoundException("IO_DirectoryNotFound_Path", new string[] { directory }); } if (IsRoot(fullPath)) { throw ExceptionUtils.GetIOException("IO_DirectoryIsRoot_Path", new string[] { directory }); } if ((showUI != UIOptionInternal.NoUI) && Environment.UserInteractive) { ShellDelete(fullPath, showUI, recycle, onUserCancel, FileOrDirectory.Directory); } else { Directory.Delete(fullPath, onDirectoryNotEmpty == DeleteDirectoryOption.DeleteAllContents); } }
public static void DeleteFile(string file, UIOption showUI, RecycleOption recycle) { DeleteFileInternal(file, ToUIOptionInternal(showUI), recycle, UICancelOption.ThrowException); }
public static void DeleteFile(string file, UIOption showUI, RecycleOption recycle, UICancelOption onUserCancel) { DeleteFileInternal(file, ToUIOptionInternal(showUI), recycle, onUserCancel); }
private static void DeleteFileInternal(string file, UIOptionInternal showUI, RecycleOption recycle, UICancelOption onUserCancel) { VerifyRecycleOption("recycle", recycle); VerifyUICancelOption("onUserCancel", onUserCancel); string path = NormalizeFilePath(file, "file"); new FileIOPermission(FileIOPermissionAccess.Write, path).Demand(); ThrowIfDevicePath(path); if (!File.Exists(path)) { throw ExceptionUtils.GetFileNotFoundException(file, "IO_FileNotFound_Path", new string[] { file }); } if ((showUI != UIOptionInternal.NoUI) && Environment.UserInteractive) { ShellDelete(path, showUI, recycle, onUserCancel, FileOrDirectory.File); } else { File.Delete(path); } }
private static void ShellDelete(string FullPath, UIOptionInternal ShowUI, RecycleOption recycle, UICancelOption OnUserCancel, FileOrDirectory FileOrDirectory) { Microsoft.VisualBasic.CompilerServices.NativeMethods.ShFileOperationFlags operationFlags = GetOperationFlags(ShowUI); if (recycle == RecycleOption.SendToRecycleBin) { operationFlags |= Microsoft.VisualBasic.CompilerServices.NativeMethods.ShFileOperationFlags.FOF_ALLOWUNDO; } ShellFileOperation(Microsoft.VisualBasic.CompilerServices.NativeMethods.SHFileOperationType.FO_DELETE, operationFlags, FullPath, null, OnUserCancel, FileOrDirectory); }
public void DeleteFile(string file, UIOption showUI, RecycleOption recycle) { FileSystem.DeleteFile(file, showUI, recycle); }
public void DeleteFile(string file, UIOption showUI, RecycleOption recycle, UICancelOption onUserCancel) { FileSystem.DeleteFile(file, showUI, recycle, onUserCancel); }
public void DeleteSelectedItems(RecycleOption recycle) { if (browser.SelectedIndices.Count > 0) { var selectedIndices = browser.SelectedIndices; string fileName = string.Empty; #region Delete one item if (selectedIndices.Count == 1) { fileName = browser.Items[selectedIndices[0]].Tag.ToString(); DeleteFileDel deleteFunc = null; if (File.Exists(fileName)) { deleteFunc = FileSystem.DeleteFile; } else/* if (Directory.Exists(fileName))*/ { deleteFunc = FileSystem.DeleteDirectory; } try { deleteFunc(fileName, UIOption.AllDialogs, recycle, UICancelOption.ThrowException); } catch (OperationCanceledException) { } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } finally { RefreshListView(); } } #endregion Delete one item #region Delete multiple items else { string text = "Are you sure you want to "; if (recycle == RecycleOption.DeletePermanently) { text += "permanently "; } text += "delete these " + selectedIndices.Count + " items?"; string caption = "Delete Multiple Items"; DialogResult dr = MessageBox.Show(this, text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { DeleteFileDel deleteFunc = null; List <Tuple <string, DeleteFileDel> > list = new List <Tuple <string, DeleteFileDel> >(); foreach (int i in selectedIndices) { fileName = browser.Items[i].Tag.ToString(); if (File.Exists(fileName)) { deleteFunc = FileSystem.DeleteFile; } else if (Directory.Exists(fileName)) { deleteFunc = FileSystem.DeleteDirectory; } list.Add(Tuple.Create(fileName, deleteFunc)); } foreach (var item in list) { fileName = item.Item1; deleteFunc = item.Item2; try { deleteFunc(fileName, UIOption.OnlyErrorDialogs, recycle, UICancelOption.ThrowException); } catch (OperationCanceledException) { } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { RefreshListView(); } } } } #endregion Delete multiple items } }
public static void DeleteDirectory(string directory, UIOption showUI, RecycleOption recycle, UICancelOption onUserCancel) { DeleteDirectoryInternal(directory, DeleteDirectoryOption.DeleteAllContents, ToUIOptionInternal(showUI), recycle, onUserCancel); }