Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do DeleteFile and FindFirstFile interact?

Tags:

c

winapi

I have a program that basically does this

while(1)
  FindFirstFile()
  if file found
    CreateFile()
    DeleteFile()

However, sometimes CreateFile reports ERROR_FILE_NOT_FOUND, even though FindFirstFile found a file! Does DeleteFile guarantee that the file won't show up in directory listings after it returns?

like image 531
Anton Lahti Avatar asked Oct 21 '22 00:10

Anton Lahti


1 Answers

You may be running into the issue described by Raymond Chen in his blog.

Basically, DeleteFile() is "kind of" asynchronous - if the file you are deleting has any outstanding file handles on it, the file system simply marks the file as "to be deleted", but it doesn't actually disappear from the directory listing until the last open handle to it is closed - even though DeleteFile returns success.

like image 128
Jonathan Potter Avatar answered Oct 27 '22 10:10

Jonathan Potter