DeleteFile fails unexpectedly
- From: jramaanv@xxxxxxxxx
- Date: 13 Jul 2005 08:52:59 -0700
Hi,
We are using this piece of code to delete a file.
HANDLE hfile = NULL;
HRESULT hr = S_OK;
WIN32_FIND_DATA FindFileData;
hfile = FindFirstFile((LPCTSTR)filename, &FindFileData);
if (hfile == INVALID_HANDLE_VALUE)
{
hr = BOERR_FILE_NOT_FOUND ;
}
else
{
bool bRetVal = FindClose(hfile) ;
if(!DeleteFile(filename))
{
CString strError;
strError.Format(_T("CFileReaderWriter::Delete : Could delete an
existing file. HR = %ld"), GetLastError());
AfxMessageBox(strError ) ;
hr = BOERR_FAILED_DELETE_FILES ;
}
}
We make sure that the file exists by calling FindFirstFile(), so if it
tries to delete the file its sure that the file exists. I find that the
error returned from DeleteFile() is '2' which happens to be "The system
cannot find the specified file". Is it possible due to some reason that
this error could come up even though the file is present.
Specific information :
* The deletion happens on a secondary thread.
* The main thread could attempt to read the file in the process while
the secondary file is deleting the file, but I have made sure
that the Critical sections are locked correctly to prevent simultaneous
access.
Also is it possible that DeleteFile could return successfully but the
file is still not deleted?
Regards,
Janakiraman
.
- Follow-Ups:
- Re: DeleteFile fails unexpectedly
- From: Christian Kaiser
- Re: DeleteFile fails unexpectedly
- From: Alexander Grigoriev
- Re: DeleteFile fails unexpectedly
- From: Gary Chanson
- Re: DeleteFile fails unexpectedly
- Prev by Date: Re: For a Data Acquisition card,Driver model to follow
- Next by Date: Re: Differences in unhandled exception handling between Windows 2000 and 2003?
- Previous by thread: WiatForDebugEvent to a process that I haven't created
- Next by thread: Re: DeleteFile fails unexpectedly
- Index(es):
Relevant Pages
|