How to delete directories with path/names too long for normal delete

387

134

Windows seems to have a length limit on file names when trying to delete, though it won't prevent those files from being created.

Our build process creates a number of temporary files (many build off of a WSDL) that run afoul of this limit. Our ant script is somehow able to delete them when doing a clean, but sometimes I need to delete the workarea directory (where all the temp files go) without actually doing a full clean from ant.

This is the same errors this question, but the answers there don't really work for me as I'm dealing with a directory, not a file, and I don't always know what specific files or subdirectories are causing the problem. And I'm trying to avoid any manual process (other than triggering a single command) to actually delete them.

If I try deleting the directory from Explorer I get the error

Cannot delete [file name]: The file name you specified is not valid or too long.  
Specify a different file name

Trying Remove-Item in powershell gives the following error:

Remove-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
At line:1 char:12
+ Remove-Item  <<<< -force -Recurse <directory>

Does anyone know of any tools or easy ways to get around this delete error without having to manually find the problem files and move/rename them?

Herms

Posted 2009-12-03T19:23:09.420

Reputation: 7 644

By Far the simplest solution: https://www.youtube.com/watch?v=qQTyTprFAOg

– TaW – 2015-11-28T21:54:10.027

using Ubuntu or any other Linux Bootable CD we can boot our computer to Ubuntu or any other OS for temporary.then we can select the folder and we can delete it easily. – Kelum Priyadarshane – 2015-11-29T04:04:33.223

1

This older question has some interesting answers too: http://superuser.com/questions/45697/how-to-delete-a-file-in-windows-with-a-too-long-filename/392431#392431

– AdamV – 2015-12-03T11:01:55.363

Ya, the simplest solution will be install 7-zip and compress it and don't forget to check the box 'Delete after compression' and then delete the zip file also. Thanks @Dentrasi. – Avishek – 2016-11-29T17:32:31.757

Actually, is there anybody who knows why Windows made such a restriction after all? It seems to make little sense since a lot of third-party tools can just circumvent this restriction with ease, so it certainly doesn't seem to be something inherent with the filesystem or whatnot. Seems to only add difficulty for the user, what for? – xji – 2017-01-12T19:10:57.730

If you happen to have IntelliJ installed, deleting the file/folder from there will work. I haven't tried any other code editors. (PS, I cannot add this as an answer due to the Protected status.) – Tormod Haugene – 2017-01-30T10:04:39.793

it is 2017, and it seems M$ don't want developer use their OS, If you are NodeJS developer, NPM may create a lot of nested folder. And you can not delete at all. – vanduc1102 – 2017-03-29T12:44:58.277

https://superuser.com/a/1263183/439537 – Andrew – 2017-10-28T00:37:42.270

2I found the solution just before posting this question, but since others may run into this I decided to post it so that they could find the solution I ran across. – Herms – 2009-12-03T19:24:39.027

Oh I know, but generally when I do things like this I leave the question "unanswered" for a while to see if anyone else has a better solution. – Herms – 2009-12-03T20:42:27.137

Answers

86

I believe I've found a way to delete things from cmd. Originally I tried the del command, but that didn't work. Then I remembered rmdir. Doing the following:

rmdir /S /Q <dir>

seems to have worked.

Herms

Posted 2009-12-03T19:23:09.420

Reputation: 7 644

For those it didn't work look at Benoit's answer on this question: http://superuser.com/questions/45697/how-to-delete-a-file-in-windows-with-a-too-long-filename

– Nishant – 2014-11-30T13:53:49.507

Didn't work for me with 10's k's of recursive folders. Only rimraf worked. – Julian Knight – 2015-09-11T10:02:34.967

it can works but it's a recursive job, you have to hit the command a lot of times. if you have to delete node folders like "node_modules" use the @jordanbtucker answer. – Luca Filosofi – 2015-10-06T12:45:18.810

It doesn't seem to work. At least not on Windows 10... – bashan – 2015-10-30T20:11:16.337

W10x64. This didn't work, but 7zipx64 did. – Mayyit – 2016-07-13T12:46:52.650

Worked for me (Windows 10) – mmey – 2016-07-27T08:59:51.950

2This solution is obtaining inconsistent results. Please, don't vote it up. – hectorpal – 2016-09-13T00:09:14.913

@hectorpal, the whole point of each user casting a single "up" or "down" vote is to ensure those that work for most people have a higher rating. So telling people (for whom this solution works) to not vote up is counter-productive to SU. – ZaLiTHkA – 2016-09-23T07:10:39.600

@ZaLiTHkA oh, good question. It's the old: straight voting vs strategic voting. Call me strategic, but I think StackExchagen is better when the voted solutions are most useful. The alternative is more noisy for the non-contributing visitors, that is the majority of readers. – hectorpal – 2016-09-28T01:47:46.410

Didn't work.... – MickyD – 2016-12-23T00:40:45.293

rd /s doesn't work if the file or path names are too long. Shift+Del in 7zip File Manager did it for me in Win10 pro. – Darr247 – 2017-06-13T00:36:10.163

This should absolutely not be the accepted answer. – defines – 2018-02-13T17:43:32.970

Nope - Windows 10. Filename too long still happens. – user922020 – 2018-08-28T15:43:49.820

105Didn't work for me. :( – Andrew Arnott – 2010-12-26T01:20:08.940

remember to drop into cmd before you attempt to run rmdir. – brianpeiris – 2012-07-13T13:16:45.677

You have to do this in the command prompt. It won't work in PowerShell unless you run it as a command prompt command from PowerShell. – Mark Rucker – 2013-05-07T13:51:49.637

9For those who are unable to use this solution I have an alternative solution that worked for me (with too long path/file names): Move the file(s)/directory to C:\ to shorten the path, then delete from there. – Anders Sandberg Nordbø – 2013-09-16T10:38:10.360

6It is possible to have directories that this solution won't work for, that 7-Zip can delete. I just had this happen to me. – SamStephens – 2013-12-18T16:07:37.357

432

Use the 7-Zip File Manager to delete them.

If you are still having trouble, ensure that you utilize Shift+Delete inside the 7-Zip File Manager. Otherwise, Windows tries to move them to the Recycle Bin (which will fail again).

Dentrasi

Posted 2009-12-03T19:23:09.420

Reputation: 10 115

16 years later, this saved me =D – thclpr – 2014-07-10T13:37:59.533

14I upvote this because with 7zip you can delete also delete a folder wich contains long nested folders inside. Had my problem with a node_module folder that contained crap tons of nested folder and I wasn't able to remove it. 7zip fixed from the base folder flawlessly. +1 – Gruber – 2014-10-13T23:33:18.660

1You can use winrar for this too.. just right click the folder and select Add to Archive. Then in Archiving Options section, select Delete files after archiving ... done.. !!!! – tarzanbappa – 2015-03-25T11:19:11.973

2I got "directory not empty" when trying to delete, but I just kept repeating, eventually, I got there and the folder is finally gone. – Malyngo – 2015-08-31T14:28:36.257

Didn't work for me with 10's k's of recursive folders. Only rimraf worked. – Julian Knight – 2015-09-11T16:40:53.700

1It amazes me how well 7-zip is programmed. I am using an apparently old version that has been released back in 2010 and could not get a single issue with it. And among other things, I use it to cleanup virus-infected flash disks because its file browser is really good! And now we have it to be able to delete long-path files! Oh, my! To whomever is behind 7-zip, thanks tremendously! – Ghasan – 2015-10-30T18:41:52.443

4Didn't work for me on win7 (with shift-del) - Get the error 'the directory is not empty' – UpTheCreek – 2016-01-21T13:44:44.180

1In case 7zip isn't an option for Windows 10 x64 users, PeaZip can do it too (and is a very goo open-source program of course). – Erick Petrucelli – 2016-02-26T21:35:45.100

This worked like a charm anb should be bundled with nodejs ;-) – hoeni – 2016-03-11T10:16:56.430

Windows 10 x64 didn't work for me. I will try this elsewhere, since I have 7Zip everywhere. – WernerCD – 2016-04-03T01:39:30.790

I'm using 7zip v15.14 (64bit)'s File Manager and I could actually RENAME the files from it! Very important you need to use: SHIFT+Delete in 7zip to delete directly, so that 7zip does not send them to the Recycle Bin! – Wasted_Coder – 2016-04-29T06:15:39.613

@UpTheCreek, when you get "Dir not empty" go down into the next subfolder (press ENTER) and press SHIFT+DEL (the topmost file/folder should be automatically selected when you go down). It will either successfully delete the file or show the same error. Keep going down until you have success then go back to the top and try to shift+delete the tree again. Usually takes about 5 or 6 levels before it works, sometimes less, sometimes more. – O.M.Y. – 2016-06-25T09:05:13.960

win10 x64 - total commander do the trick with shift+del – gsziszi – 2016-08-11T09:01:02.623

6Thanks - this got rid of a dir tree that went a bit recursive and was too deep for del/rmdir/rm/explorer to remove – Martin Beckett – 2010-08-24T15:47:47.420

7zip didn't work for win7 64 – CodeTweetie – 2018-02-15T12:32:55.183

Funny that Microsoft Windows can't take care of the files in file system but 7zip can! – xbmono – 2018-04-17T23:16:37.280

I think this is the only write answer. Nothing else worked for me. Just rename it with 7-zip manager and delted it. thank you so much – Arundev – 2018-07-12T14:59:15.713

I can't believe this is the best answer. How do we delete files from Windows USING WINDOWS??? – pabrams – 2019-08-16T21:11:40.870

67worked great using shift+Del - 7zip couldn't send long-pathed files to the recycle bin.... – cori – 2011-03-02T03:44:12.337

69+1 7zip. You have to navigate to the folder, and THEN use shift + Del like @cori said. If you select the Delete option from the context menu, it WILl fail there. shift + Del it! – Urda – 2012-06-20T21:25:46.983

@Urda I'm getting this error message (Data error - cyclic redundancy check) when shift-deleting a long-pathnamed directory with 7-zip. Have you or anyone else encountered it?

– galacticninja – 2013-03-26T09:16:46.107

I tried a bunch of explorer replacements, but all of them just seemed to pass delete requests to the default explorer mechanism, so I gave up. Never thought to use 7zip as an explorer replacement though. I'll have to give it a try. – Herms – 2009-12-03T20:41:51.647

2In addition to SHIFT + DEL, 7-Zip provides the Menu Bar/View/Flat View option which in my case was able to list the directories of a supposedly recursive path when cmd or Explorer didn't show anything. – dgs – 2013-11-21T10:22:28.103

47zip just got awesomer – Nahn – 2014-05-06T07:21:20.207

87zip didn't work for win7 64, so linux did. – Erik Friesen – 2014-05-15T20:09:20.143

311

None of the other (free) answers here worked for me, but I found one on another site:

rimraf <dir>

rimraf is a Node.js package, so you will need to install Node.js which includes npm. Then you can run:

npm install -g rimraf

Then you can run rimraf from the command line.

I found this solution because npm itself was causing this problem due to the way it nests dependencies.

By the way, rimraf gets its name from the UNIX command rm -rf, which recursively deletes files and folders.

jordanbtucker

Posted 2009-12-03T19:23:09.420

Reputation: 3 483

7Tried many ways. This just works perfectly! – Duckegg – 2015-11-17T13:14:08.853

2The best answer of all :) yes its easy beasy – Al-Mothafar – 2015-12-08T12:47:50.587

Worked for me as well.... – PHPCoder – 2015-12-18T09:50:07.263

1Hmm, didn't remove my directory, or give any error. – UpTheCreek – 2016-01-21T13:55:26.223

This is the correct and the best answer – Faraj Farook – 2016-02-06T18:40:00.977

Didn't work at first, Error: EPERM: operation not permitted, unlink '<dir>/<subdir>'. I renamed the folder I was trying to delete, re-ran it, then it worked – BenVlodgi – 2016-02-16T22:10:32.517

2This should be the accepted answer. – NINCOMPOOP – 2016-03-10T06:44:28.357

2+1 internet point for you. NPM nested dependencies all the way down to hell for me as well. – WernerCD – 2016-04-03T01:38:39.207

14Your solution works but this is so f##k-up that I have to use a node js module for deleting node js modules folders... I do not want to live on this planet anymore – Benoit P – 2016-09-23T10:04:23.450

4Node created the problem in the first place for me so... interesting... that they also have a solution. – Eric J. – 2016-09-27T16:43:09.437

1Worked swimmingly. npm had also caused this issue for me and rimraf was able to blow away the invalid files very quickly. – Derek Evermore – 2016-09-29T14:37:04.853

Didn't work throws error EPERM: Operation not permitted, unlink PATH at Error <native> – Saif – 2017-05-06T15:00:49.007

The Error was because of, the folder was accessed by other application, closing it and running the command worked – Saif – 2017-05-06T15:07:34.110

Make sure to run cmd as Administrator – gdx – 2017-08-04T11:12:41.493

One would expect these problems to be part of the dark ages of windows. Instead ... – 99Sono – 2017-08-18T06:48:31.360

Works like charm .Superb answer bro – Don Chakkappan – 2017-10-05T10:45:51.307

Funny thing, blaming node for windows not being able to handle path names longer than 256 characters. – ohcibi – 2017-11-20T20:10:00.733

@ohcibi That's like saying we shouldn't blame humans for the extinction of species that can't adapt after their homes have been destroyed. – jordanbtucker – 2017-11-20T20:15:36.137

155

There is no need to install any program for solving this issue.

This issue is easily solved using robocopy, preinstalled since Windows Vista, launched in 2006.

For example, rmdir /S /Q <dir> has been reported to fail in some cases. There is no need to use 7zip or any other 3rd party tool. Powershell is an overkill. Cygwin may work, but you may not have it installed. So, let's focus on robocopy

The idea is to

  1. use robocopy to copy+updated
  2. from a new empty folder
  3. to the folder you want to delete, the target.

After executing robocopy, the target directory would be empty as well.

These instructions are for the command line. Just open the search in Windows, type cmd and hit Enter.

Let’s say the target for deletion is:

C:\delete\this folder\with a very long name

We proceed as follow:

  1. First create an empty directory, f.i. C:\emptyfolder.

    mkdir C:\emptyfolder
    
  2. Copy+update from the empty directory to the target, using the option /purge

    robocopy c:\emptyfolder "C:\delete\this folder\with a very long name" /purge
    
  3. Delete the empty directory. You don't need it anymore.

    rmdir c:\emptyfolder
    

Since there are no files or folders in the source directory (C:\emptyfolder), it simply deletes the files and folders under the target directory (C:\delete\this folder\with a very long name) recursively!

  • Final trick: you can avoid writing by hand

    C:\delete\this folder\with a very long name
    

    By dragging the folder from an Explorer window and dropping in the Terminal/cmd window.

Be careful: The deleted files will not go to the trash folder! Once deleted, the files cannot be recovered.

(Taken from "Path too long? Use Robocopy" by BVLANGEN)

PS: I realize this answer was here, less didactically. How to delete a file in Windows with a too long filename? [duplicate]

Benoit added:

You may need to go through this process more than once to get rid of all of the files.

hectorpal

Posted 2009-12-03T19:23:09.420

Reputation: 1 843

13Thank-you good sir!! This should be the accepted answer as all the others either didn't work or required a 3rd party tool. :) – MickyD – 2016-12-23T00:44:43.723

This works perfectly...no need to install anything (as far as I know) and it's quick. This should be the accepted answer! – ksumarine – 2017-01-06T17:01:49.537

1This keeps some (or all) of the directory tree under "c:\deletefolder" (target dir). Anyway, deleted everything in a blink for me (guess the files were small) and I just had to manually <Del> "c:\deletefolder", the child dirs got removed without an issue. Worked like a charm. +1, should be the accepted answer! :) – rld. – 2017-01-15T13:45:53.367

@rld, but did "deletefolder" exist before? Otherwise, I think it should be empty if it was a new directory. Otherwise it's a mess. I could add a last step for "rmdir deletefolder". – hectorpal – 2017-01-16T17:11:06.203

@hectorpal 1. I had a tree with remains of a Windows C drive backup from another machine, that I managed to delete except for the very long parts, ie. "%USERPROFILE%/foo/very_long_dirname/vldn2/vldn3/(...)/very_long_filename". 2. cd ~; mkdir empty; robocopy empty foo /purge 3. Was left with ~/foo/maybe_something_deeper_too_cant_remember/ and didn't really take time to investigate further because I was already pissed at M$ for disrespecting me and wasting my time, but a simple <Delete> on ~/foo in explorer removed it successfully, after failing endlessly (even with ownership) until robocopy. – rld. – 2017-01-18T18:22:34.923

I might add, "foo" being "deletefolder" and "empty" being "emptyfolder" – rld. – 2017-01-18T18:29:04.053

@rld. It seems the robocopy failed, but it should have complaint. It would have been interesting to run robocopy /purge again. – hectorpal – 2017-01-27T15:14:04.253

THIS IS THE BEST SOLUTION, IT WORKS PERFECTLY, NONE OF THE REST WORKED FOR ME! THIS ONE DOES!!! – Krzysztof Cichocki – 2017-02-18T21:36:28.817

I believe I know 95% of Windows guts but still surprised by Microsoft's talent to inject this kind of "features" when in order to delete file you have to either install Node.js (Node.js, man, the server-based Javascript engine made by a company non-existing at the time when Windows was created!) + packages with a hundred dependencies - basically you have to do everything except of straightforward rmdir /s /q *

@hectopal nevertheless, thank you for the answer using Windows built-in tools. – maoizm – 2017-04-05T08:07:35.893

Didn't work for me. It moves files, but the resulting directory couldn't be removed (still long paths in it) – steph643 – 2017-05-08T09:56:55.393

@steph643 Could it due to a permission issue? – hectorpal – 2017-05-09T18:14:32.327

I guess it's complicated – Alex78191 – 2017-06-01T02:08:50.260

Robocopy looked like a winner for me, but it crashed when it hit some other internal limit. The last successfully reported path was 5666 characters. – Timbo – 2017-06-12T17:44:11.673

Wow. I'll try to do it in Python. https://stackoverflow.com/a/10620762/204981

– hectorpal – 2017-06-12T21:06:44.040

awesome! I prefer this because no 3rd party dependency. Thanks very much !!! – abhi – 2017-11-23T13:08:55.157

This should be the accepted answer :) – defines – 2018-01-31T21:02:12.010

1When dealing with highly recursive directories, this option is much slower than 7zip. After waiting 20 minutes, I benchmarked them and realized 7zip, albeit doesn't show progress was running 50x faster. – Andy Gauge – 2018-08-22T22:25:35.723

While the other answers are useful this is the best answer as it requires no additional tools. md C:\empty robocopy c:\empty c:\Target /purge /NFL /NDL >nul &Rem CMD robocopy c:\empty c:\Target /purge /NFL /NDL >$null # powershell – HerbM – 2018-12-02T20:23:18.940

1I agree with @MickyD: this should be right at the top as the accepted answer! I am now routinely using my "designated empty directory": robocopy C:\Users<me>\empty <Whatever_directory_needs_emptying> \purge >nul Although I like robocopy diagnostics when synchronizing directories, I want to delete things in silence... – Flandraco – 2020-02-28T17:55:53.203

30

The tool that I used when I had this problem was FastCopy. I selected Delete All from the dropdown, selected the the directory I wanted to delete, and clicked Delete All.

FastCopy delete dialog screenshot

FastCopy is portable (no install required), and there are 32 bit and 64 bit versions available.

braveterry

Posted 2009-12-03T19:23:09.420

Reputation: 783

3

If you are looking for a command-line tool, you could use a small tool I've published on GitHub (https://github.com/epsitec/Tools-RecursiveDelete).

– Pierre Arnaud – 2015-03-27T06:10:20.830

I had a recursively generated set of nested file/folder. This was the only solution working – Pierluigi – 2015-11-26T13:15:31.407

2This worked for me when, the command line stuff failed, the 7zip attempt failed. and even Microsoft support was stumped! – Kit Ramos – 2016-03-25T04:02:34.273

Same here - I kind of started to delete files with 7zip, but it also acted very weird and I had to Shift+Delere each directory multiple times in a row to actually delete it, but then I tried this tool, and worked like a charm. Launched it twice to get rid of all files. Thanks! – Artanis – 2016-05-30T20:47:16.383

Thanks, for me as well the only working solution, GREAT!!!! – tim – 2016-06-12T11:27:00.400

That's great.It worked very well for me. – Fereydoon Barikzehy – 2016-09-06T11:33:15.877

Nothing worked, but this did! – demonkoryu – 2017-01-09T22:21:01.617

Stumbled on this when every other solution including robocopy failed for deeply nested dirs, but choked on some dirs the same way Shell (using Mobaterm) did. But seems like a better option for comparing/sync'ing dirs. Will give it a shot, hope it works better than BeyondCompare, which hogs the CPU. Thanks for the link ! – killjoy – 2017-12-30T13:48:03.270

perfect! This is a tool im not going to forget! – Adsy2010 – 2020-01-22T20:31:21.737

26

Cygwin's rm -rf works well on long paths!

gdw2

Posted 2009-12-03T19:23:09.420

Reputation: 1 025

3Cygwin worked for me perfectly! Just did a -rm -rf and all the files got deleted. – Ranhiru Jude Cooray – 2014-10-23T04:42:42.363

3Worked for me as well under GNU bash, version 4.1.10(4)-release – anonymous – 2015-09-22T04:13:54.123

2Worked great when running from a Git Bash command window. I had installed GitGui for that. – None – 2016-08-30T15:48:31.780

26

Without installing additional software you can use subst command to temporary create an alias to a long named directory.

e.g. If you want to delete folder C:\Very long directory\that exceed\length limit\blah blah blah\abcde\folder to be deleted you can use the command

subst x: "C:\Very long directory\that exceed\length limit\blah blah blah\abcde"

and then you can delete X:\folder to be deleted in Windows Explorer or in command prompt easily. To remove the temporary drive letter alias use the command

subst x: /d

Kenneth L

Posted 2009-12-03T19:23:09.420

Reputation: 12 537

I tried all other answers (including answers from other similar questions) and this was the only one that ended up working for me. And it was by far the fastest. – glenneroo – 2017-05-26T12:54:17.473

1This is by far the best answer: simple, built-in features, no messing round with the registry. Should be the accepted answer. – Kevin Roche – 2017-09-12T15:01:34.193

Easily the cleanest and most straightforward method, thank you Kenneth. – Seth – 2018-06-13T16:25:58.197

Uh this answer scares me because I actually have an X: drive. There isn't enough information here and I do not recommend people follow this without further explanation. – qodeninja – 2019-09-09T02:31:34.630

22

Just drop from Powershell into command by running below:

Cmd /C "rmdir /S /Q <dir>" 

Karl Glennon

Posted 2009-12-03T19:23:09.420

Reputation: 361

3"The directory is not empty". Oops. The OP wants to delete a non-empty folder. – leye0 – 2016-04-23T23:19:52.923

how is this different to @herms' answer ? – bigbadmouse – 2018-09-11T10:22:22.450

18

Dentrasi's solution is what worked best for me, but I wanted to post the specific steps in a top-level answer.

  1. Download and install the latest stable build of 7zip.
  2. Run the 7zip File Manager (7zfm.exe).
  3. In the 7zip File Manager, navigate so that you can see the name of the folder you want to delete (i.e. you're in the parent folder).
  4. Hold the Shift button down.
  5. Click the "Delete" button, either on your keyboard or in the 7zip File Manager toolbar; make sure you're still holding the Shift key down.
  6. Click the "OK" button; make sure you're still holding the Shift key down.

Mass Dot Net

Posted 2009-12-03T19:23:09.420

Reputation: 341

Nice try but still didn't work for me with 10's k's of recursive folders. Only rimraf worked. – Julian Knight – 2015-09-11T16:40:24.610

@JulianKnight: Yeah, this approach didn't end working for me 100% of the time, either. I just wanted to mention it because it was among the more straightforward processes, and it at least worked part of the time.

The only thing I've found that that has worked 100% of the time is the Powershell + NTFSSecurity module script approach, which I described below.

IIRC rimraf failed when called, which is how I got into this mess in the first place. See this Node.js thread for details: https://github.com/nodejs/node-v0.x-archive/issues/6960#issuecomment-46704998

– Mass Dot Net – 2015-09-14T05:38:23.233

Yes, there will always be problems like that. In fact it was the Arduino IDE's library installation code that did me in (Java), I accidentally selected the folder containing the libraries as a folder to install a library from and off it went! I killed the process as soon as I realised but already had 10's of k's of folders (damn i7/SSD!) The next main release of NPM is meant to help resolve many of the deep library installation issues for Node as dependencies should be met from a much flatter structure. Still I'm really glad someone put me on to rimraf - easy and free. – Julian Knight – 2015-09-18T08:22:12.370

@JulianKnight - Yep, a day or two ago somebody told me that npm3 should help to alleviate these problems by preventing deeply nested dependency folder structures. – Mass Dot Net – 2015-09-27T21:38:18.727

Don't know whether it "prevents" but it does treat nested dependencies more sensibly so that if your main app requires library X v1.0 and library Y requires Z which also requires X v1.0, the top level library will be used. Currently Z would install its own version of X. – Julian Knight – 2015-09-28T14:00:28.737

@JulianKnight: So yes, "mitigate" would probably be a better description -- it doesn't solve the problem, but it will hopefully make it a less common problem on Windows than it is today. – Mass Dot Net – 2015-11-11T05:16:19.523

Worked for me (win 7 x64). I messed up with the library folder of my project in Netbeans and it created a /lib/lib/lib/... path that seemed to be thousands of subfolders deep!! – Broken_Window – 2016-03-08T22:55:16.720

12

There are two things not already mentioned in the existing answers.

  1. You can use extended length path prefix to access long paths
  2. With Windows 10, you can enable long path support for general use - note however, that not all applications will work with long paths, you should test older software. Only software with an appropriate manifest entry will be able to make use of this.

Long Path Prefix

The Windows API has a special function that supports Unicode path names up to 32k characters long (each element being up to 255 characters in length).

This is often mistakenly referred to as UNC naming but it isn't though it is related.

The prefix used to tell the API to use long Unicode paths is \\?\ as in:

\\?\D:\very long path

UNC names are normally used when referring to paths on remote servers in the form \\servername\path name\file name. You can combine this with the long path prefix so: \\?\UNC\server\share

Note that some, poorly written but sadly quite common, applications do not support UNC file paths nor the long path prefix.

Reference: https://msdn.microsoft.com/en-gb/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath

Long path support

This is an option that has been added to recent versions of Windows 10. It is not, at the time of writing, activated by default since it requires specific application support. Interestingly, PowerShell has support built in so enabling this option will allow long paths to be used directly in PowerShell scripts.

You can activate it via the Group Policy editor if you have a version of Windows with that. Or you can simply use the following Registry change. As always, please back up the section of the registry you are changing before doing anything.

  1. Run regedit.exe.
  2. Confirm the UAC prompt.
  3. Navigate to the key: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy Objects\{48981759-12F2-42A6-A048-028B3973495F}Machine\System\CurrentControlSet\Policies
  4. Create or change the key LongPathsEnabled.
  5. If it does not exist, right-click on Policies and select New > Dword (32-bit) Value from the menu.
  6. Set LongPathsEnabled to 1 to enable.

Any applications with appropriate manifest entries will now have access to POSIX standard long paths. This should include Windows Store apps.

Reference: https://blogs.msdn.microsoft.com/jeremykuhne/2016/07/30/net-4-6-2-and-long-paths-on-windows-10/

UPDATE 2017-04-09

@maoizm pointed out an issue with the registry key above so I did some more digging. It looks like you can now set long filename support with a system key:

HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD)

This still only works for applications that are specifically set to use it though (requires an entry in the application's manifest.xml).

You should also note that you cannot use relative path names with this method.

Julian Knight

Posted 2009-12-03T19:23:09.420

Reputation: 13 389

{48981759-12F2-42A6-A048-028B3973495F}Machine part of registry path will be different at each computer - it might be not obvious to everyone – maoizm – 2017-04-05T13:00:51.610

1@maoizm - good point, thanks for highlighting that. Please see my update for an alternative if using the W10 Anniversary update or later. – Julian Knight – 2017-04-09T13:44:56.467

I am writing a library called FoundationIO, and I'm trying to make the long path the default, is there any function I can call or macro I can set to make long path support automatically enabled for any user of my library? – MarcusJ – 2018-06-04T02:49:44.793

Hi Marcus, is this a native Windows library? If so, .NET has the required support already present as part of the relevant Windows API - sorry that I don't know the details as I'm not a .NET or Win API programmer but the details should be searchable on MSDN. – Julian Knight – 2018-06-08T12:23:28.773

8

I like the cmd solution. Although I want to share another workaround that even works in just Explorer: try to shorten the names of the parent folders before deletion: shorter names will shorten the path. Say, you have this tree structure of the folder:

C:\

.. Projects

.. .. Some Awesome Project during spring 2014

.. .. .. Some Activity in the park in the city a friday

.. .. .. .. Bla bla bla bla bla bla bla bla bla bla bla bla

.. .. .. .. .. Actual files with long names, too

In this case you cannot delete the folders, you cannot delete or rename the files neither. If you want to remove the whole folder structure or part of it, you can temporarily rename the parent folders and shorten the path, and then remove the folder. The names can be just letters:

C:\

.. Projects

.. .. x

.. .. .. y

.. .. .. .. z

.. .. .. .. .. Actual files with long names, too

In my case I just wanted to remove the whole folder with many subfolders and files. So I didn't care about folders' names.

Anatoly Mironov

Posted 2009-12-03T19:23:09.420

Reputation: 751

1

I've written a tiny tool that does just that and put it up to GitHub. https://github.com/epsitec/Tools-RecursiveDelete

– Pierre Arnaud – 2015-03-27T06:07:57.880

1All commands or Shift+DEL doesn't work for me, but this does. – larkee – 2015-07-21T12:35:53.790

Doesn't really work when you have 10's k's of nested folders – Julian Knight – 2015-09-11T16:39:36.083

also doesn't work if one of the folders has a really long name (you can't rename the offending folder). – aucuparia – 2017-11-21T12:06:18.207

7

The 7-zip solution works great. Another option if you have git installed is to open a bash shell and use:

rm -f

(or rm -rf for folders)

User

Posted 2009-12-03T19:23:09.420

Reputation: 2 430

1For the uninitiated please explain how you "open a bash shell" in Windows? – O.M.Y. – 2016-06-25T11:30:34.873

1@O.M.Y. you need git installed. Then from start menu you can open git bash or if you opted to have the shell extensions when you installed git then you can right click in or on a folder and select Git Bash Here – User – 2016-06-25T11:36:28.857

4

I suggest Total Commander (shareware, but keeps working after trial period with only a minimal nag start screen). That is the way I allways solve the too long filename issues.

Sopalajo de Arrierez

Posted 2009-12-03T19:23:09.420

Reputation: 5 328

1Thank the lord I found this. Having issues deleting a node_modules folder because it decides to stupidly nest the directories. – Alias – 2014-08-14T09:27:08.883

Well, @Alias, Total Commander makes that issue easier to detect, at least for me. After identifying such problem, chkdsk should solve it. – Sopalajo de Arrierez – 2014-08-14T09:59:26.307

Version 7.0 doesn't work, it shows an error message and suggests doing operation as Administrator, which fails as well. – izogfif – 2016-01-21T15:36:27.740

@izogfif : latest version as for today is 8.52a. I would try this one. You don't give details about your error message, but you could have some inconsistency on archive structure that must be solved (for NTFS at least) with "chkdsk c: /f" (assuming drive C:). – Sopalajo de Arrierez – 2016-01-22T00:27:25.590

2

You can also delete them using their equivalent short name. dir /x will show you them.

Ian Boyd

Posted 2009-12-03T19:23:09.420

Reputation: 18 244

2

I created a simple java program that uses robocopy to delete the files. The jar is a runnable one. For additional output run it from cmd line.

https://drive.google.com/file/d/0B5pSEjxJvt_1WVp1T3puSm1CNjg/view?usp=sharing

CamHart

Posted 2009-12-03T19:23:09.420

Reputation: 186

2

And if you do not want to use Java, you could use this tool I wrote using .NET (https://github.com/epsitec/Tools-RecursiveDelete).

– Pierre Arnaud – 2015-03-27T06:09:20.430

@PierreArnaud great utility. I needed something like this for command line automation. @ CamHart good work from u too! Thanks guys! – amitthk – 2017-01-20T04:30:12.613

1

Bigger Directories is designed for this task as well. enter image description here

  • Download
  • Uses a recursive call with RemoveDirectoryW to delete existing directories
  • Uses own file repository for newly created directories
  • Files can be moved from the directories prior to deletion of containg directories.
  • Speedy, although navigating to top of directory is a click per nested directory
  • Windows XP(SP3) and up
  • Unsigned unmanaged code without installer, so possible Smartscreen warning when run from spare folder e.g. desktop.

More info at CodeProject.

Laurie Stearn

Posted 2009-12-03T19:23:09.420

Reputation: 344

Please read How do I recommend software for some tips as to how you should go about recommending software. You should provide at least a link, some additional information about the software itself, and how it can be used to solve the problem in the question.

– DavidPostill – 2017-01-09T12:38:59.027

@David: Better? Link was very useful, thanks. – Laurie Stearn – 2017-01-10T10:35:34.337

1

I faced this issue in Windows 10 and found this easy solution.

  1. Go in to little deeper of your folder tree.
  2. Drag and drop a folder from somewhere middle of the tree to somewhere begin of the tree using address bar.
  3. As in my image drag and drop red box to green box. (in this case path is shorter, but for long paths it works as well)
  4. Then your path become shorter and delete as normal using using delete key.

enter image description here

Nayana Adassuriya

Posted 2009-12-03T19:23:09.420

Reputation: 203

1

Got the perfect answer here (for files). Works in Windows 10.

REM Make sure there is no \ at the end of either path!
robocopy "C:\...\...\...\long\path" "C:\DeleteMe" "FileName" /MOV
REM Note: this ^ can be called many times before...:

REM Finally, recursively delete the higher up DeleteMe directory.
rmdir /S /Q DeleteMe

See also: https://msdn.microsoft.com/en-us/library/aa365247.aspx#maxpath

Not a single alternative answer in 4 questions was sufficient for my needs. You're welcome world.

Andrew

Posted 2009-12-03T19:23:09.420

Reputation: 175

1

I've tried all the other answers, but they didn't work (atleast for me).

I came across delinfile and worked quite well and pretty quickly!

It's trial is limited to 3 actions / 15 Days but it's usable if you only wanted to delete a few folders/files:

Jürgen Paul

Posted 2009-12-03T19:23:09.420

Reputation: 715

0

If you have Bash on Ubuntu on Windows installed, you can cd to the parent directory in a regular command prompt and then type:

bash -c "rm -rf dirname_here"

Which launches bash, recursively deletes the directory from linux where there are no filename restrictions, and then exits back to your regular command prompt.

Richard Szalay

Posted 2009-12-03T19:23:09.420

Reputation: 611

0

Navigate to the directory in WinRAR, select the file, press F2, rename the file to a shorter name. Then you can delete the file as usual.

Source: https://www.youtube.com/watch?v=qQTyTprFAOg

root

Posted 2009-12-03T19:23:09.420

Reputation: 272

0

I finally found out how to do this via Powershell. Here are the instructions I followed for getting this to work on Windows 7:

  1. Create a new folder called NTFSSecurity in the folder C:\Users\XXXX\Documents\WindowsPowerShell\Modules\NTFSSecurity, where XXXX is your Windows username. Example: if my username was "aspnyc", the new folder would be C:\Users\aspnyc\Documents\WindowsPowerShell\Modules\NTFSSecurity .

  2. Download the File System Security PowerShell Module package - it should be available as a simple ZIP file.

  3. Open up a Powershell console, run Get-Module -ListAvailable and make sure NTFSSecurity shows up somewhere in the list of registered modules.
  4. In the Powershell console, run Import-Module NTFSSecurity .
  5. In the Powershell console, run Remove-Item2 "YYYY" -Recurse , where YYYY is the Windows path to the folder you want to recursively delete (e.g. C:\Potatoes\Badgers\FolderToDelete ).

Mass Dot Net

Posted 2009-12-03T19:23:09.420

Reputation: 341

0

I finally found out how to do this with Powershell on Windows 10 where the individual filenames were too long. Here are the steps I followed for getting this to work on Windows 10:

  1. Download the File System Security PowerShell Module package - it should be available as a simple ZIP file.
  2. Extract the Zip file as a folder NTFSSecurity in the directory C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules.
  3. Open up a Powershell console with the administrative elevation (a.k.a. Admin Mode) and run Get-Module -ListAvailable and make sure NTFSSecurity shows up somewhere in the list of registered modules.
  4. Run Set-ExecutionPolicy Unrestricted to bypass the signed execution mode. You have to confirm this action with a Y(es)
  5. Eventually cd to the folder that you want to delete.
  6. In the Powershell console, run Import-Module NTFSSecurity .
  7. In the Powershell console, run Remove-Item2 "YYYY" -Recurse , where YYYY is the relative or absolute Windows path to the folder you want to recursively delete (e.g. C:\Potatoes\Badgers\FolderToDelete ).
  8. Check if it worked.
  9. Eventually set back to signed execution mode with Set-ExecutionPolicy Restricted. You have to confirm this action with Y(es).

Epicurist

Posted 2009-12-03T19:23:09.420

Reputation: 127