10

How to delete large file path/file name files in Windows. Which is slimier to Linux rm -rf . ?

Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25
  • 1
    Ashish, while I laud your desire to increase the collective knowledge of StackOverflow, this is (due to its non-programming nature) probably more suited to SuperUser. So I (and a few others by the looks of it) are nudging it over to there. – paxdiablo May 20 '17 at 04:50
  • https://superuser.com/a/1263183/439537 – Andrew Oct 28 '17 at 00:37

2 Answers2

34

To delete The file name is too long. errors files, we've to go for simple steps using default command of Windows robocopy and rmdir.

  1. Create directory mkdir deleteLongFilesDir under C: or D: drive
  2. Suppose D:\Development\Liferay\themes directory contains the files which are not able to delete simply.
  3. run command in command prompt robocopy D:\deleteLongFilesDir D:\Development\Liferay\themes /purge , this command will print some logs and copy you all the files and sub directory of D:\Development\Liferay\themes into deleteLongFilesDir folder virtually, but when you open that directory... hurreeee...It's Empty ???
  4. Now run the command of remove directory which we created for mapping rmdir deleteLongFilesDir from command line.
  5. Now temporary directory has been deleted and same as for D:\Development\Liferay\themes files and folder.
Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25
  • This worked! Thanks! I had a NetBeans Java build\classes directory with filenames containing nearly infinite number of repeated 'classes\build' in the paths. This ran for about 10 minutes and showed no sign of stopping, so I Cntrl-C then re-ran the robocopy command and it completed in less than a minute. After the rmdir command, all was well - empty classes directory! After completion, my D: drive had 46 MB additional free space. Weird. – RickC Aug 11 '18 at 04:18
  • Finally! I've never been that happy to see my files disappearing. – hopsinat Feb 07 '20 at 08:00
  • This worked like a charm. Great help. Thanks – Darthchai Apr 14 '20 at 22:47
  • This solution works and is correct, but the explanation is wrong. `robocopy` synchronizes the empty folder into to the target folder while purging the target folder (deleting files that are not present in the empty source, thus all). – stackprotector May 14 '20 at 11:56
1

There is a Powershell cmdlet named Remove-Item2, written by Boe Prox a well-known MVP, and which circumvents the basic limitation path of 260 characters.

https://gallery.technet.microsoft.com/scriptcenter/Remove-LongPathFile-7a4db495

Additionally, like Remove-Item2, there are other cmdlets suffixed by the number 2, like Get-ChildItem2, which are often included in popular third party modules, and also addresses the 260 characters limitation. If you have installed some of these modules, there is a chance that you have already those cmdlets on your computer.

Luke
  • 1,734
  • 2
  • 15
  • 18