Deleting files and folders used by other processes on Windows

tkondal at gmail.com tkondal at gmail.com
Tue Jul 17 14:21:21 EDT 2007


Hi,

I have been looking into making my file cleaning script more
intelligent.  The goal of the script is to delete everything on a
drive except for a couple of folders which are skipped by the script.
Recently, I noticed that some files where not being deleted because a
process was using them.  Is there a recipe (needs to run on Windows XP/
2003) for doing the following (more specifically, I need a way to
determine which process is holding a lock on my file):


file=GetFilename();
bLock = IsThereAFileLockOnFile(file)
If (bLock)
{
 process = GetLockingProcess(file);
 TerminateProcess(process);
}
DeleteFile(file);



Thanks.




More information about the Python-list mailing list