Deleting files and folders used by other processes on Windows

tkondal tkondal at gmail.com
Wed Jul 18 16:13:52 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