July 31, 2017

How to Delete Folders with Long Paths that Windows Can't Delete

How to Delete Folders with Long Paths that Windows Can't Delete


The horror of “Cannot delete [file name]: The file name you specified is not valid or too long. 
Specify a different file name
 
Hello every one and welcome to another post to Explain something that you may or may not know already.

How to Delete Folders with Long Paths that Microsoft Windows Operating Systems (GUI) do not know how to handle.


Background;

Sometimes Some Programs can create deep long paths of folders and files that exceed the 256 characters that Microsoft Operating Systems don't know how to handle (User interface Wise).

For Example;
  1. if you are using a software application that categorizes your Pictures by multiple categories like Date Picture taken and name of First Tagged Person and Street name from Geo Tags which could lead to a very long name like; "C:\users\username\My Pictures\2017.07.31\My Brothers Long Name\My Street Name from Geotagging which is a bit longer than usual\The final File name which consists of the date and time as part of the name and maybe the geolocation street name too.jpg" This example shows how easy it is to have a path that exceeds the default max of 256 characters.
  2. When you are using a music tagger / organizer like "Music Brains Picard" and for example try to tag a classical album this for sure will lead to the same problem.

SO, WHAT TO DO,

Well for me I suffered from these multiple times and I will list underneath possible resolutions in no particular order of difficulty.

  1. If you only have a couple of folders and/or files you can try to rename them to short names at that point you will be able to delete easily
      1. “C:\Long folder name\Another long folder name\and another\and another\long file name too.jpg”
      2. Start renaming from top to bottom every long name rename to 1 or 2 letters or numbers and travers down and then you will be able to delete them easily.
  2. If you find it easy to boot from an external Boot Disk with a Live Linux Distro you can just navigate to the folder location and delete the folders you want to delete then boot to windows normally after and all will be well. "The only Down Side is if you (Like Me) have your files on a Raid Array (Specially Fake Raid or Mother Board Provided free Raid) at that point your Linux distribution might not easily recognize the Raid Drive thus making it more time consuming to let your Linux read the Raid Array so it is easier to try other solutions.
  3. You can Use 7Zip which is a totally free application to Un Compress files like *.RAR, *.ZIP, …etc.  From within the application navigate to the folder in question and Press “SHIFT and DELETE” not the delete button only as delete button will use the windows delete and will not be able to accomplish what is needed but when you click the “SHIFT and DELETE” combo the application itself can do that for you.  You can check out this YouTube video https://www.youtube.com/watch?v=qQTyTprFAOg which was not created by me so props to the author for it which shows you an example in a very easy way.
  4. And here we come to the magic trick “ROBOCOPY” which is built in windows so no need to install anything, I discovered this solution from SuperUser technical forum https://superuser.com/questions/78434/how-to-delete-directories-with-path-names-too-long-for-normal-delete reply number 74 explained it excellently and I will summaries underneath;
    1. Let’s say you have a very long pathed folder called “C:\Very Long Path Folder that I want to delete”
    2. Create an empty folder on lets call it delete
      1. (mkdir C:\del)
    3. Copy and update the date from the empty directory/folder to the Folder that you want cleansed. 😊
      1. (Robocopy C:\del “C:\Very Long Path Folder that I want to delete” /purge)
      2. The switch /purge will copy and update the folder as the source folder which was already empty.
    4. Now you can delete your empty directories / folders easily with no fuss.
    5. Since there are no files or folders in the source directory (C:\del), it simply deletes the files and folders under the target directory (C:\Very Long Path Folder that I want to delete) recursively!

So now you know it.


I did not re-invent the wheel, this was the efforts of others and since it took me long to find out how I decided to summarize all in one topic and tried my best to give props to those who had articles or steps for doing so.

No comments:

Post a Comment