public static bool DeleteFileOrFolder(string destination, bool permanent, bool silent) { try { var fs = new Native.Shell32.SHFILEOPSTRUCT { wFunc = Native.Shell32.FileOperationType.FO_DELETE, pFrom = destination + '\0' + '\0', }; if (!permanent) { fs.fFlags |= Native.Shell32.FileOperationFlags.FOF_ALLOWUNDO; } if (silent) { fs.fFlags |= Native.Shell32.FileOperationFlags.FOF_NOCONFIRMATION | Native.Shell32.FileOperationFlags.FOF_NOERRORUI | Native.Shell32.FileOperationFlags.FOF_SILENT; } Native.Shell32.SHFileOperation(ref fs); return(true); } catch (Exception) { return(false); } }
public static bool MoveFiles(IEnumerable <string> items, string destination, bool silent) { try { var fs = new Native.Shell32.SHFILEOPSTRUCT { wFunc = Native.Shell32.FileOperationType.FO_MOVE, pFrom = string.Join("\0", items.ToArray()) + '\0' + '\0', pTo = destination + '\0' + '\0' }; if (silent) { fs.fFlags |= Native.Shell32.FileOperationFlags.FOF_NOCONFIRMATION | Native.Shell32.FileOperationFlags.FOF_NOERRORUI | Native.Shell32.FileOperationFlags.FOF_SILENT; } int result = Native.Shell32.SHFileOperation(ref fs); return(true); } catch (Exception) { return(false); } }