c# - 如何标记要删除的文件夹 C#

标签 c# windows

当系统重新启动时,我如何使用 C# 将一个文件夹标记为删除。

谢谢,

最佳答案

来自:

http://abhi.dcmembers.com/blog/2009/03/24/mark-file-for-deletion-on-reboot/

文档:

https://learn.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-movefileexa#parameters

///
/// Consts defined in WINBASE.H
///
[Flags]
internal enum MoveFileFlags
{
    MOVEFILE_REPLACE_EXISTING = 1,
    MOVEFILE_COPY_ALLOWED = 2,
    MOVEFILE_DELAY_UNTIL_REBOOT = 4, //This value can be used only if the process is in the context of a user who belongs to the administrators group or the LocalSystem account
    MOVEFILE_WRITE_THROUGH  = 8
}


/// <summary>
/// Marks the file for deletion during next system reboot
/// </summary>
/// <param name="lpExistingFileName">The current name of the file or directory on the local computer.</param>
/// <param name="lpNewFileName">The new name of the file or directory on the local computer.</param>
/// <param name="dwFlags">MoveFileFlags</param>
/// <returns>bool</returns>
/// <remarks>http://msdn.microsoft.com/en-us/library/aa365240(VS.85).aspx</remarks>
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll",EntryPoint="MoveFileEx")]
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName,
MoveFileFlags dwFlags);

//Usage for marking the file to delete on reboot
MoveFileEx(fileToDelete, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);

关于c# - 如何标记要删除的文件夹 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1007184/

相关文章:

C# 从套接字读取错误的数据

c# - 修改或隐藏表单的标题工具提示

windows - 批处理脚本循环以检查多个参数

windows - WiX:在 ProgramFilesFolder 中安装应用程序会引发 AccessDenied 异常。为什么?

c++ - 应该使用什么 MAPI 属性来设置 "Always prompt for logon credentials"属性?

c# - 在将文件流式传输给用户时在 ASP.NET(通过服务器)中下载文件

c# - Windows 窗体应用程序中不同线程中的 GUI 和逻辑分离

c# - Umbraco 工作提要 rss

java - UDP 传输后将字节编码数据转换回 int32 的问题

c# - 从 Url 中获取子字符串