I am writing a service for Windows (from XP to 8.1). I need to recursively delete a folder and I use DeleteFile and RemoveDirectory for that. I don't want to use SHFileOperation because it has the MAX_PATH limit.
The problem is that sometimes, RemoveDirectory fails with ERROR_DIR_NOT_EMPTY, even if the directory is empty. I found out that this is because DeleteFile works asynchronously, it only "marks" a file for deletion. Therefore, adding a small delay (Sleep) before calling RemoveDirectory fixes the issue. But I am looking for a cleaner method.
So, is there a way to ensure that the marked files are well and truly deleted?
I already tried to call FlushFileBuffers directly on the directory, without success.
Aucun commentaire:
Enregistrer un commentaire