標籤:
//////////////////////////////////////////////////////////////////////////
//函數: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;
}
windows 不可恢複式的刪除檔案