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.5 (8 votes)

Comments

DanN74's picture

I ran into this same issue when trying to remove a borked box.com sync folder. Box will allow for absurdly long file names, and I suspect this was the root cause as well. This technique literally gave me back about 40GB of hard drive space! I was about to do a clean install or buy a new drive. Thank you so much.

awgiedawgie's picture

This is not a Windows 10 bug. Beginning with Windows 95, when Windows began allowing long file names, it has always restricted the full path name to 260 characters.

Windows 10 - as of the Anniversary Edition (aka version 1607) - actually allows you to disable this restriction, effectively giving you unlimited path name length (technically, it's still limited to 32,767 characters by the NTFS file system itself, but no one in their right mind will ever come anywhere close to that).

The problem with this is that many older programs, particularly 32-bit programs, still won't respect or recognize anything longer than the old 260 character limit, so enabling long path names could end up causing you more problems that it solves.

hasting's picture

thanks for share

Richard.E's picture

Hey, new guys here. You have the most comprehensive solution to this trouble that I've been able to locate AND it's relatively recent. Seems related to my trouble, but not 100% so I figured I'd piggy-back on this post.

If you don't want the background, please skip to the 'rmdir' portion below:

I have a scheduled task running some VBScript running a snapshot backup process.Two scripts run: 1) Renames the first <FolderName> on the <LinuxNAS> to an even longer <FolderName Temp01> in order to get it out of the way so it can copy the backup files to a new folder named <FolderName>. Later that night, there's a second process which comes in and looks for folders named <FolderName Temp##> and deletes them. (Part of the trouble here is that the user is remote and the process can run 12+ hours, so they frequently ended up interrupting the deletion process, so I needed to get the copy done first, then worry about deletions)

Originally, I mapped drives to the source and target folders so I worry less on whose computer it's running, meaning the mapping is a hold-over from the original code, partially in place to reduce the characters needed to reference the filename(s). But, it's the Drive Letter (H:) mapped to "\\<LinuxNAS>\<UserName>\"

RMDIR: The pseudo-command below is what's being run:

rmdir /S /Q H:\FolderName Temp01\Folder\Folder\FolderName

RETURNS:

H:\FolderName Temp01\P3KBJB~5\Local\Jobs\MMoA-01\Pages\26WEX3~4 - The system cannot find the path specified.
H:\FolderName Temp01\P3KBJB~5\Local\Jobs\MMoA-01\Pages\A4G8OS~C - The system cannot find the path specified.
H:\FolderName Temp01\P3KBJB~5\Local\Jobs\MMoA-01\Pages\A06RBP~V - The system cannot find the path specified.

(etc, etc, etc, many thousands of times)

FILENAMES: If you notice, there are tildes in the sub-foldernames. Interestingly the parent folder DOESN'T... I have confirmed, the following:

These are the short names for their respective folders
The overall lengths of the filenames (without the shortnames) never exceeds 200 chars, Even if I substitute the full path instead of the drive letter.
There are no special characters in any of the filenames, except those that generally don't cause trouble (like "+", "-", "_" - less the quotes).
Not all filenames include the 'safe' special characters, so even that's covered.

OPTIONS:

I can delete the folder in any myriad of ways, from right-click > Delete, to dragging it to the recycle bin, to pressing the delete key....permissions is not the trouble.

SERVER:

This is a Linux-based NAS that you may want to point to as the source of the trouble, but (and this MAY be key here) it's only happening with the remote user. There are two other users whose files are targeted by this same code and they never have any troubles. It is a WD My Cloud EX4100, no info on the precise OS, but I'm sure it's some open-source stuff pilfered by WD for re-sale >:-( I Digress...

This is lengthy and I apologize for that. It's just that these types of posts are frequently (DARN-NEAR-ALWAYS!!!) misunderstood and there's more time spent getting across exactly what the trouble is when assumptions are made about the problem. So, I try to explain as much as I can in advance of the misunderstanding.

Richard.E's picture

This is an article, not a post...hmmm.