Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DeleteFile function

Status
Not open for further replies.

fatlardo

Programmer
May 7, 2007
41
GB
I have a problem using the DeleteFile function in Delphi 2006.

I am using the following code:

Code:
DeleteFile(path + '\' + rec.name);

I have checked and the argument does represent a valid file.

The function returns false.

GetLastError returns 0 (no error)

The file has not been opened by the function I call DeleteFile from. It has been opened and read by a function called by this function but it is closed before the function terminates.

Also, I copy the file almost immediately before trying to delete it.

Help!!!!!

 
If the path is valid, then the only other explanation is that the file is locked. What sort of file are we dealing with? Windows has processes that occasionally lock video files for example.

You might try adding a Sleep(1000) command before trying to delete it, just in case any of the open/close routines you're using are non-blocking.

Maybe try pausing at the point where you're trying to delete the file with a breakpoint, and then see if you can manually delete the file yourself. That will tell you for sure whether the file is locked at that point.
 
Also File handling errors are generaly handled differently to the errors returned by getlasterror.
Have a look at IOResult


Steve [The sane]: Delphi a feersum engin indeed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top