How to Fix: Path too Long, Cannot Delete

Dennis Faas's picture

Infopackets Val G. writes:

" Dear Dennis,

Recently my Windows 10 machine failed to update, resulting in an infinite boot loop (Startup Repair). I knew I had to reinstall Windows, but backed up the data first using Macrium Reflect. After that I tried to copy the data back from the disk image backup (using copy and paste), but each time Windows Explorer would crash during the file copy. I tried Robocopy to copy the data and this worked - however, I kept receiving errors such as: 'C:\Temp\Users\Default User\AppData\Local\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data is too long.' I have tried to delete these long directories but get an error from Windows stating that 'the filename or path is too long and cannot be deleted.' I tried using the command prompt but get the error that 'The system cannot find the path specified'. I've tried suggestions over at reddit but nothing will delete the paths. Can you help? "

My response:

I asked Val if she would like me to connect to her machine using my remote desktop support service in order to have a closer look, and she agreed.

Below I will discuss my findings.

How to Fix: Path too Long, Cannot Delete

After much research into this problem, it appears that the reason why Val could not copy the files using file explorer (via the copy and paste technique) is because of the long path issue. This doesn't play well with File Explorer, which then causes it to crash.

The reason the path is so long is due to severe Windows corruption. In this case, it's caused by something I call a "circular file reference" - because the same path is pointing to itself over and over, nested inside the original path. I've seen this many, many times before when I'm hired to fix a client's machine - usually from a failed Windows Update. In Val's case, this file system corruption likely took place well before the update installed, which then caused the update to fail, and ultimately resulting in an infinite boot loop.

Moving on!

Unfortunately, none of the methods mentioned at Reddit were able to fully fix the problem of not being able to delete the long paths. That said, the suggestion to use Robocopy /purge definitely helped, along with using a great program I've been using for years, called TreeSize Free. It's my understanding that the Robocopy /purge made the folder contents 0 bytes, which then made it easier for TreeSize Free to delete the long paths.

Here are the steps I took:

  1. Download and install TreeSize Free if you haven't already.
     
  2. Next, launch an administrative command line. Click Start, then type in "cmd" (no quotes); wait for "CMD.EXE" or "Command Prompt" to show up in the list, then right click it and select "Run as Administrator".
     
  3. Launch Notepad. Click Start, then type in "notepad" (no quotes), then click it when it appears in the list.
     
  4. Using File Explorer or some other means, navigate to the beginning of the long path you wish to delete, then copy and paste the path into Notepad.

    In Val's example, the full long path is C:\Temp\Users\Default User\AppData\Local\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application Data.

    Therefore, the beginning of long path that cannot be deleted is C:\Temp\Users\Default User\AppData\Local\Application Data\Application Data\.
     
  5. Next, highlight the text below using your mouse:

    C:
    cd \
    mkdir poop
    robocopy \poop\ "[insert your long path here]" /purge
    rmdir \poop
    echo this is a dummy line
     
  6. Right click the above highlighted text with your mouse and select "Copy". Now, go to the Notepad you opened in Step #3 and click Edit -> Paste on a new line (being careful not to overwrite the path you pasted previously). The text you copied above should be pasted into Notepad.

    You will now need to substitute the "[insert your long path here]" with the beginning of the long path you cannot delete, which should also be pasted into your Notepad. Important: when you substitute the [insert your long path here], leave the double quotes before and after the long path.

    Using Val's example, the text would now read:

    C:
    cd \
    mkdir poop
    robocopy \poop\ "C:\Temp\Users\Default User\AppData\Local\Application Data\Application Data\" /purge
    rmdir \poop
    echo this is a dummy line
     
  7. Now it's time to execute the above commands. In Notepad, click "Edit -> Select All," then "Edit -> Copy" to copy the text into your clipboard. Next, navigate to the command prompt you opened in Step #2, right click in the middle of the window, and select "Paste". The text you copied from Notepad should now be output to the command line.

    Note: at this point, the folders have been purged of files, but the directories themselves have not yet been deleted (described in Step #9). In this case, please keep a note of each path to delete in a separate Notepad file.
     
  8. Repeat the process for other paths too long that you cannot delete normally.
     
  9. Now it's time to permanently delete the long paths.

    Launch TreeSize Free if you haven't already, and copy one of the long paths from Notepad into your clipboard. In TreeSize Free, click the "Select Directory" icon at the top left of the screen, then paste the long path into the "Select folder" window. This will take you to the long path directory that you want to delete.
     
  10. Next, left click to highlight the folder delete, the press and hold SHIFT + DEL together to have TreeSize free delete it permanently.
     
  11. Voila - the long path is now deleted. Repeat the process for as many long paths that need deleting.

I hope that helps.

Additional 1-on-1 Support: From Dennis

If all of this is over your head, or if you need help deleting long paths that won't delete, I can help using my remote desktop support service. Simply contact me, briefly describing the issue and I will 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: 5 (11 votes)

Comments

hasting's picture

Thanks