gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 12:59:09 25 4
gpt4 key购买 nike

当系统重新启动时,我如何使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com