Quick Fix: Cannot Delete File In Use?

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.

Log

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..

Advice

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…

Search

The file is located, and we can see that the wlcomm.exe process has a handle open to the file we searched for.

result

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.

About Robert Pearman
Robert Pearman is a UK based Small Business Server enthusiast. He has been working within the SMB IT Industry for what feels like forever. Robert likes Piña colada and taking walks in the rain, on occasion he also enjoys writing about Small Business Technology like Windows Server Essentials or more recently writing PowerShell Scripts. If you're in trouble, and you can find him, maybe you can ask him a question.

Leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: