How to Fix: Can't delete file / folder: 'The system cannot find the file specified'

Dennis Faas's picture

Infopackets Reader Tom T. writes:

" Dear Dennis,

I recently had to reinstall Windows and I'm trying to clean up the root directory of my C drive to keep things tidy. I have a Windows.old.000 folder that I would like to remove, but every time I try to delete it, I get a window that says 'You need permission to perform this action' and nothing gets deleted. I've tried ccleaner (crap cleaner) and check marked the 'Delete old windows installation' option (under the Advanced menu), but that doesn't work, either. What do I have to do to remove the Windows.old.000 folder and its contents? "

My response:

I suspected this is likely a permissions issue, essentially resulting in an 'Access Denied' error message. Sometimes deleting a folder and its contents can be tricky, especially if the system keeps giving you strange error messages - just like the "The system cannot find the file specified" error. As such, I asked Tom if he would like me to connect to his system using my remote desktop support service. Tom agreed, and what I found was quite an interesting problem.

First, I'll explain what I did in simple English. Then, I'll provide very detailed and easy to follow instructions, so that you can do the same, should you ever encounter "The system cannot find the file specified" error.

Dealing with the 'The system cannot find the file specified' Error

The first thing I did was to reset the discretionary access control lists and ownership on the files and folder recursively using the 'icacls' and 'takeown' programs. In 99% of most cases, this will fix the issue - but in Tom's case, it did not.

I then reviewed the directory structure of the Windows.old.0000 folder and noticed it contained many subfolders. Based on my experience, I can tell you that Windows 10 does not like long path names when it comes to renaming or deleting folders. I have never encountered this issue before with previous editions of Windows, and therefore I suspect this is actually a Windows 10 bug. The solution here is to manually go through the directory tree and substitute all the folders for shorter paths. For example: if I was trying to delete a folder with the path name c:\thisfolder\has\a\really\long\path, then the solution is to rename it to c:\thisfolder\a\b\c\d\e, then delete c:\thisfolder. Unfortunately, this didn't work for Tom, either.

With respect to the above scenario - another thing that pops up sometimes is if the folder name contains a special bit character that prevents the system from being able to recognize the folder name and successfully delete it. For example, you may have a folder whose name does not contain any letter in the alphabet, but instead looks like a series of symbols. Attempting to delete such a folder (often from the command line) may result in a 'file not found' error. The solution here is to rename the folder to something else using the Windows graphical user interface (via the desktop) and then try to delete it. Unfortunately, this did not apply to Tom's case - but it's worth mentioning.

The last thing that I tried was to enable the Administrator user account, then sign on as the the Administrator, then open up an administrative command prompt. From there, I reset the discretionary access control lists and ownership using the Administrator user, then recursively deleted the folders. Strangely enough, I received multiple "file not found" errors while carrying out this task, however, the files and folders were deleted successfully. The lesson to learn here is that even if you are signed in as your user and even if you open up an administrative command prompt to carry out a task (such as resetting file permissions) - it takes signing on as the Administrator user to actually make it happen - especially when it comes to flaky permission issues.

Below I'll explain step-by-step how what I did using simple English - in case anyone else has the same issue.

How to Fix: Can't delete file / folder: 'The system cannot find the file specified'

  1. First, bookmark this page as you will likely need to come back to it. Next, run CHKDSK (checkdisk) on the drive to ensure that your file system is not dirty (which can also prevent you from deleting a file or folder). To do so: click Start, then click "My Computer" or "This PC"; go to the C drive, then right click it and select "Properties" from the dialogue menu. Next, go to the Tools tab and click the "Check" button under the "Error checking" heading. You may be prompted to restart the system - if so, do that and come back to this page (don't forget to bookmark, first!).
     
  2. Next, open an administrative command prompt, and we'll try and reset the discretionary access control lists and ownership on the files. To do so: click Start, then type in "cmd" (no quotes); wait for "CMD.EXE" or "Command Prompt" to appear in the list and select "Run as Administrator". A black administrative command prompt window should now appear.
     
  3. Please note and highlight the appropriate commands below.

    If you are trying to delete a single folder or a folder with multiple subfolders and files, use your mouse to highlight the text below:

    c:
    cd \
    takeown /f "ENTER FULL PATH HERE AND KEEP THE QUOTES" /r /d y >out.txt
    icacls "ENTER FULL PATH HERE AND KEEP THE QUOTES" /reset /T >out2.txt
    rmdir /q /s "ENTER FULL PATH HERE AND KEEP THE QUOTES"
    echo this is a dummy line

    If you are trying to delete a single file, use your mouse to highlight the text below:

    c:
    cd \
    takeown /f "ENTER FULL PATH HERE AND KEEP THE QUOTES" /d y
    icacls "ENTER FULL PATH HERE AND KEEP THE QUOTES" /reset /T
    del /f /q "ENTER FULL PATH HERE AND KEEP THE QUOTES"
    echo this is a dummy line
     
  4. Next, right click over the highlighted text above and select "Copy" from the dialogue menu. Now, click Start and type in "Notepad" (no quotes); wait for Notepad to appear in the list and click it. In the Notepad window, click Edit -> Paste; you should see the text you just copied in Step #3 appear in Notepad. You will need to edit the lines of text that read "ENTER FULL PATH HERE AND KEEP THE QUOTES" to match the file or folder you wish to edit.

    For example, if the folder you wish to delete is c:\Windows.old.000, then replace "ENTER FULL PATH HERE AND KEEP THE QUOTES" with "c:\Windows.old.000", keeping the quotes around the full path. If you want to delete a single file, make sure the entire path ends in the file you want to delete. For example, if I wanted to delete "thisFile.exe" which resided in c:\temp, then the full path is: "c:\temp\thisFile.exe".

    IMPORTANT: only proceed to the next step if you are 100% sure you want to modify the permissions on the file / folders you just specified in Notepad. If you enter in the wrong path and change access control and ownership, you will undoubtedly corrupt something. In this case you are welcome to contact me for additional 1-on-1 support, and I can carry out the task for you; otherwise, PROCEED AT YOUR OWN RISK.
     
  5. Next, highlight all the text in Notepad and then right click over top it, then select Copy from the dialogue menu. This will place the modified text into your clipboard. Now, go to the administrative command prompt you opened in Step #2 and right click in the middle of the window, then select "Paste" from the dialogue menu. This will paste everything you entered into the Notepad onto the command line and hopefully the files and folders will also be deleted. If not, proceed to the next step.
     
  6. If the folder you are trying to delete is still present, go through the directory structure and shorten the folder names to single characters (like "a", "b", "c", etc). Don't forget to rename the parent directory as well. After that, try deleting the folder again. If you are trying to delete a single file, try renaming it, then try deleting it. If it still won't delete, proceed to the next step.
     
  7. Bookmark this page if you haven't already as you will need to sign on as the Administrator user to continue. You should also copy the URL of this page into your clipboard and paste it into a Notepad file, as you won't easily be able to access your bookmarked page for the current user once you are signed on as the Administrator user.

    To do so: first, save the Notepad file you have with the commands in it (taken from Step #3), as you will need to use it again. To do so: make a folder on the C drive and call it "Temp", then go to Notepad and save the file as "c:\temp\commands.txt".

    Now it's time to copy the URL of this page and save it to Notepad, so you can come back to it after you're signed on as the Administrator user. To do so: go to the address bar of your web browser, and click on the URL which contains the web address of this page. Next, press CTRL + A on the keyboard to select the entire URL, then right click over the highlighted text and select "Copy" from the dialogue menu. Next, open a new Notepad file, then select Edit -> Paste; then save the file to C:\temp\url.txt. When you sign in as the Administrator user, you can open both the "c:\temp\commands.txt" and "c:\temp\url.txt" for your convenience.

    Next, highlight the text below using your mouse:

    net user administrator /active:yes
    echo this is a dummy line

    Right click over the highlighted text above, then select "Copy" from the dialogue menu. Next, go to the administrative command prompt and right click in the middle of the window. The text you just copied should be output to the command line and the Administrator user should be active.
     
  8. Next, sign out of the current user and login as the Administrator user. To do so: click Start -> Shutdown, then Log off. You will be logged off; at the sign in page, click the Administrator user account. There is no password to enter for the Administrator user, (unless you previously set one).
     
  9. Once you are signed on as the Administrator user, repeat Steps #1 through #4 (also using your "c:\temp\commands.txt" file) and this should delete the files and folders. If it does not, you are welcome to contact me for additional support, described next.

Additional 1-on-1 Support: From Dennis

As you can see by these instructions, deleting files and folders with an error message that says "The system cannot find the file specified" can be tricky - because the system is essentially telling you that the files and folders you're trying to delete don't exist, when in fact they do. If you find these instructions too technical or otherwise need help deleting some files and folders with the "The system cannot find the file specified" error - I can help using my remote desktop support service (for a nominal fee). Simply contact me briefly describing your message and I'll get back to you as soon as possible.

Got a Computer Question or Problem? Ask Dennis!

I need more computer questions. If you have a computer question -- or even a computer problem that needs fixing - please email me with your question so that I can write more articles like this one. I can't promise I'll respond to all the messages I receive (depending on the volume), but I'll do my best.

About the author: Dennis Faas is the owner and operator of Infopackets.com. With over 30 years of computing experience, Dennis' areas of expertise are a broad range and include PC hardware, Microsoft Windows, Linux, network administration, and virtualization. Dennis holds a Bachelors degree in Computer Science (1999) and has authored 6 books on the topics of MS Windows and PC Security. If you like the advice you received on this page, please up-vote / Like this page and share it with friends. For technical support inquiries, Dennis can be reached via Live chat online this site using the Zopim Chat service (currently located at the bottom left of the screen); optionally, you can contact Dennis through the website contact form.

Rate this article: 
Average: 4.2 (5 votes)