Quick Fix: Cannot Delete File In Use?
March 14, 2012 Leave a comment
I am testing a PowerShell script to delete files based on age, as Acronis ‘Backup Location CleanUp’ seems hopeless at this task on this particular network – seems to work ok on others.
I found a neat little script here, http://gallery.technet.microsoft.com/Delete-files-older-than-x
It was working, but failing to delete one file in particular giving me the error that the file was in use.
So what to do?
Well i didn’t have any applications open, and i logged off and logged on again just to be sure.
I tried to delete it manually through Windows Explorer, and sure enough i got the same error.
I hit Google and turned up this piece of sage advice…(not Sage as in the program, Sage as in ‘a sage’) …anyway, it suggested to use trusty Process Explorer..
Sure enough, fire up Process Explorer, hit CTRL-F and enter the name of the file in question..in my example I’ll use a random file as i already unlocked and deleted the file i was having a problem with…
The file is located, and we can see that the wlcomm.exe process has a handle open to the file we searched for.
Hopefully if you are ever stuck trying to delete a file, and you cannot see why it is locked – this will help point the way.
It definitely saved me a lot of trouble!
Thanks go to Mike K, whoever you are, wherever you are, the internet Sir, is grateful.