|Home | Games | Awards | About | Blog | Press Kit | Contact|
By: Matthew Doucette
Every so often you will encounter a stubborn file or folder that cannot be deleted in Windows and/or DOS. Fortunately, there are clever ways around the blockade.
If you succeed or not, I welcome you to post your experience in our forums.
Typical Error Messages:
The first of two typical Windows messages:
Cannot delete XXXXXXXXXX: Access is denied.
The second of two typical Windows messages:
Cannot delete XXXXXXXXXX: It is being used by another person or program.
The typical DOS command line message:
The process cannot access the file because it is being used by another process.
Warning: Delete files off your computer at your own risk. Xona.com is not responsible for any and all damages that you cause to your computer or yourself by following the directions on this web page.
End the Locking Process
This is our first suggestion as typically files can not be deleted because they are in use. Usually the reason the file is in use is because it is a part of a program (or locked by a program) that is running. Sometimes the program that is running is a piece of spyware that you want to get rid of. The first step is to shut down this spyware program that is running. Skip by this, if this is not the case.
Press Ctrl-Alt-Delete to bring up Windows Task Manager. Go to the Processes tab. Search for the processes that should not be running. (We can not give advice on which processes these are. We hold no responsibility if you accidentally delete something you should not have. Please proceed at your own risk. This document is on how to delete the file, not how to determine which process is which software!)
Sometimes the names of spyware are easy to find, but sometimes they are cryptic or randomized on purpose. If in doubt, research the file on Google, like this one:
Once you delete the process, you can (sometimes) delete the files associated with the process.
Shut Down "explorer.exe" and use DOS
If that doesn't work, sometimes the file is locked by "explorer.exe" itself, which is Explorer. Explorer is not Internet Explorer. Explorer is the Windows graphical user interface. If you shut it down, you will lose things such as your Start menu, your taskbar, etc. Shutting it down will not damage your system, as explorer.exe can be thought of as just another program that is running.
Now, use Windows Task Manager to shut down "explorer.exe". Don't worry, Windows will not crash. You will be limited in what you can do for the time being, but Windows Task Manager can bring Explorer back up.
Now, after you have shut down "explorer.exe", go to "File" and "New Task (Run...)" in Windows Task Manager. Now, type in "cmd" and press enter.
Now you are in a DOS Prompt console program. From here, you can delete files without using Windows Explorer and other programs that require explorer.exe to be running. If you remember, it was probably explorer.exe that is "using" the file you want to delete, and thus blocking you from doing so... this solution allows you to shut down Explorer, and thus remove the "in use" property of the file, allowing you to delete it.
To navigate around your computer in DOS (Windows Task Manager, "File", "New Task (Run...)", type "cmd", and press enter), use the following commands:
cd \ ________________________ go to drive root
Play around with these commands and get comfortable with them. It is the only way you will learn.
To delete the files, use the following commands:
del FILE_NAME_HERE __________ deletes specified file
To delete folders (directories), use the following commands:
rd FOLDER_NAME_HERE _________ removes (deletes) folder if empty (contains no files)
Once you have removed the files and folders, go back to Windows Task Manager and run "explorer.exe" to bring back Explorer. Go to "File" and "New Task (Run...)" in Windows Task Manager and type in "explorer.exe" It's that easy!
Delete the file or folder using the DOS names:
Sometimes a file is stored with a name that is invalid to Windows. I had a file that ended with two periods and Windows could not access it. I had to find out what the underlying DOS name was, and delete it in DOS using the DOS name.
Use the following command to show the DOS names of your files and folders:
dir *.* /x __________________ lists files and folders in DOS name format
Output from this command shows that "Favorites" is stored as "FAVORI~1" in DOS. You can access files and folders with Windows-invalid names by using the DOS name instead of the Windows name.
Delete File Before Locking Process Starts Via Batch File
If you can not shut down the process that is locking the file you want to delete, here is a method of deleting the file before the process gets a chance to lock it. As I have no idea what process and what file you are trying to delete, you may follow these directions at your own risk.
For the purpose of this tutorial, I will assume that the file you want to delete is "toolbar.dll" and it is located at "C:\Program Files\Toolbar". In other words, I will show you how to delete "C:\Program Files\Toolbar\toolbar.dll".
The extension ".bat" determines batch files. A batch file is a list of DOS commands that are executed when the batch file is executed.
REM Delete Batch File
The "del" command is the deletion command. The "pause" command pauses so that you can see what happens before the batch file window closes. The quotations are used as "Program Files" contains a space that will be misinterpreted as two separate words without the quotations. You may use any DOS commands in this batch file. You can see the commands I have chosen are to delete "C:\Program Files\Toolbar\toolbar.dll". Pay attention to what you try to do. "rd" cannot remove directories that are not empty, for example.
Check to see if "C:\Program Files\Toolbar\toolbar.dll" is deleted. It should still exist as the process should still be locked. If the file is deleted, then you could have deleted it without using a batch file. To be explicit, a batch file does not posses special powers to delete files that you do not have yourself. A batch file can be executed at a time when the file-locking process is not running. This is the purpose of using a batch file.
Why execute the batch file now, when it doesn't work? Executing the batch file now lets you see what the batch file looks like when it runs, so it does not confuse you in the future.
As it says, press any key to continue. The batch file will then stop running and close down.
Now, let's run this batch file when the process is, hopefully, not running...
A Windows Explorer window should open up that is exploring "C:\Documents and Settings\USERNAME\Start Menu\Programs\Startup".
You should see "delete.bat" existing in your "Startup" directory. Now your batch file will run "on startup", when your computer 'starts up' from being shut off or rebooted. Hopefully it will run before the process that locks the file runs.
This is when you can tell if it worked or not.
Please post in our forums to let me know if this works (for you).
Infinite Loop Batch File
Robert Melenyk suggested another idea which worked for him. The files he wanted to delete contained the process executable file itself! Even if that's not your case, it may be a worth while method to attempt on your stubborn, undeletable files. Here's Robert's tip:
Boot into safe mode (press F8 on reboot) and create an infinite loop batch file. (We will use "C:\Program Files\Toolbar\toolbar.dll" as the example file again.) Here is the batch file code:
REM Infinite Loop Delete Batch File
Change the center line to delete what needs to be deleted on your system. Then, run the batch file and end the process that is locking the file(s) in question. The file(s) should get deleted!
Use Another Operating System
Magus suggested another idea, which works for him all the time. If you have two operating systems installed (even if it is the same operating system as the original) then boot into the other operating system and delete the file. The lock on the file that previously stopped you from deleting it will be gone! Thanks, Magus.
Use "Process Explorer" To Find Locking Process
Download Process Explorer (freeware) to identify which program has a particular file or directory open. This is perfect for identifying the process that is, potentially, locking your file.
In Dan's situation, the offending application had already closed down, but Process Explorer allowed him to inspect the file handles of the improperly locked file. This pointed him to two handles that were locking the file he wished to delete. It "worked like a charm". :) Thanks for the tip, Dan.
Show Locked Files of a Process:
To set Process Explorer to show its locked files, choose "Show lower pane" under the "View" menu. When you select or highlight a process in the upper pane, the lower pane will show the locked files. Remember, you must choose the process to find the file it is locking, you cannot do the reverse and choose the file to find the process that is locking it.
File Contained Within a Zipped File?
Windows' file search returns files that are contained within a zip files. This can be confusing. A file contained within a zip file can only be accessed if you extract it from the zip file. It is not immediately obvious, from the Windows' search results, which files are stand alone (regular) files and which are files contained inside zip files. Please check out this thread to see how misleading this can be: Win XP Search Assistant finds non-existing files.
Fan Feedback: Use "GiPo@MoveOnBoot" to Move or Delete File in Next System Boot
As suggested by Jason Hurlbert in our forums, you may wish to check out GiPo@MoveOnBoot. It will copy, move, or delete files and folders in the next system boot, when the files and folders are not locked by other applications.
Fan Feedback: Boot in Safe Mode and use “del /S”
"Quinones, IT1 (SW/AW)" wrote me with another solution:
I recently ran into the same error/problem.
About the Author: I am Matthew Doucette of Xona Games, an award-winning, indie game studio that I co-founded with my twin brother. We make arcade-style intense retro games. Our business, our games, our technology, and we as competitive gamers have won prestigious awards and received worldwide press. Our business has won $180,000 in contests. Our games have ranked from #1 in Canada to #1 in Japan, have become #1 best sellers in multiple countries, have won contests, and held 3 of the top 5 rated spots in Japan of all Xbox LIVE indie games. Our game engines have been awarded for technical excellence. And we, the developers, have placed #1 in competitive gaming competitions relating to the games we make. Read about our story, our awards, our games, and view our blog.
Xona Games, Xona.com, Xonatech, Saw Tooth Distortion, Evolutionary Prototype (EP), Duality ZF, Decimation X, Decimation X2,
Decimation X3, Decimation X3.5, Decimation X4, Score Rush, Score Rush 2, Score Rush MP, and Score Rush Extended (Score Rush EX)
trademarked and copyrighted by Xona Games Inc., Jason Doucette, and/or Matthew Doucette.
© 2000..2005 Saw Tooth Distortion.
© 2008..2010 Xona Games (under Xona.com).
© Xona Games Inc.
We make Intense Retro video games.