API删除文件
2020-12-13 05:34
标签:style blog color 文件 io for div ar API删除文件,搜素材,soscw.com API删除文件 标签:style blog color 文件 io for div ar 原文地址:http://www.cnblogs.com/cause/p/3873222.htmlusing System;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("kernel32.dll")]
public static extern uint DeleteFile(string fileName);
[DllImport("kernel32.dll")]
public static extern uint GetLastError();
[DllImport("kernel32.dll")]
public static extern uint FormatMessage(uint dwFlag, ref IntPtr source, uint messageId, uint languageId, ref string lpBuffer, uint size, ref IntPtr va_list);
static void Main(string[] args)
{
string str = null;
IntPtr tempptr = IntPtr.Zero;
if (DeleteFile("C:\test.txt") != 0)
Console.Write("删除成功!");
else{
FormatMessage(0x1300, ref tempptr, GetLastError(), 0, ref str, 0, ref tempptr);
Console.Write("删除失败!\n失败原因:" + str);
}
}
}
}
下一篇:python游戏练手--贪吃蛇