windows 不可恢复式的删除文件

来源:互联网 发布:耽美网络剧百度云链接 编辑:程序博客网 时间:2024/06/06 02:15
//////////////////////////////////////////////////////////////////////////
//函数:EraseFile
//参数:strFilePath(文件的全路径)
//功能:不可恢复删除单个文件
//时间:
//////////////////////////////////////////////////////////////////////////
BOOL EraseFile(LPWSTR strFilePath)
{
HANDLE hfile = INVALID_HANDLE_VALUE;
BOOL bok = FALSE;
char ZeroBuf[512];
int index = 0;


ZeroMemory(ZeroBuf, sizeof(ZeroBuf));
do
{
SetFileAttributes(strFilePath, FILE_ATTRIBUTE_NORMAL);
hfile = CreateFile(strFilePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);

if (hfile == INVALID_HANDLE_VALUE)
{
break;
}

DWORD nsize = GetFileSize(hfile, NULL);

int nWriteCount = nsize / sizeof(ZeroBuf);
nWriteCount = max(nWriteCount, 1);
DWORD dwBytes = 0;

for (int i = 0; i < nWriteCount; i++)
{
WriteFile(hfile, ZeroBuf, sizeof(ZeroBuf), &dwBytes, NULL);
}

index++;
CloseHandle(hfile);

} while (index < 1);

bok = DeleteFile(strFilePath);
return bok;
}
0 0
原创粉丝点击