//////////////////////////////////////////////////////////////////////////
//函数: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;
}
时间: 2024-11-25 15:51:16