also for Windows if you use FILE_FLAG_BACKUP_SEMANTICS you can directly call CreateFile on a directory, keeping a handle open to it without requiring any files (i dont know if you need special user permissions for that, apparently SE_BACKUP_NAME privilege using AdjustTokenPrivileges if youre not Admin)
Code: Select all
sPath.s = "c:\temp\deltest"
CreateDirectory(sPath) ;create in case it doesnt exist
hDir = CreateFile_(sPath, #GENERIC_WRITE, #FILE_SHARE_WRITE, 0, #OPEN_EXISTING, #FILE_FLAG_BACKUP_SEMANTICS, #Null)
If hDir
MessageRequester("Test", "Handle now open to " + sPath + " (shouldnt be able to delete)")
Else
MessageRequester("Error", "Couldnt open " + sPath)
EndIf
;CloseHandle_(hDir) ;can delete it after this
A similar but i guess less flexible approach is to use SetCurrentDirectory which also seems to keep a handle open
I cant test Linux/OSX at the moment but can you delete a directory if a process has an open handle to a file within it?
or if you have a little Sleep.app binary running from a directory, can you delete the directory?