Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Recursivly delete empty folders

Jul
3
0
Pieced this together as I was looking to clean up.

alias CleanDirs = del /s/e/x/y /nest THISISJUSTAPLACEHOLDER.NOTAREALFILENAME

Hope it makes it into the Google Search machine and helps someone else!
And... the order of the command line switches makes it easy to remember ... SEXY NEST :cool:
(ya.... at times I'm still a 13 year old kid!)
 
I've used del /s /e /x /y con.* — knowing that Windows will not allow filenames to match a device name.

And I've seen others using something like del /a:d /s /e /x /y * on the theory that DEL deletes files, and no file will have the Directory attribute set. (Test with caution; I'm not certain of the syntax for that approach.)

Want to prevent the top-level directory from being removed? Switch to it with PUSHD before your DEL, and POPD out afterwards. You can't remove the current directory.
 
Hi Charles,

I didn't expect a reply, but thanks for affirming that I'm not the only one who still loves the power of TCC in 2021! :)
And... I am more mature than you might gather from my nickname... not much... but ;)

del /s/e/x/y /nest THISISJUSTAPLACEHOLDER.NOTAREALFILENAME

I didn't mention one of the reasons I loved the above version is it gives very nice clean output of what directories have been removed.

Run this for a sample, anyplace on your drive. First two commands create a mess of empty directories.
md ThisIsATest\Some Directories have Spaces\But this Shouldn't matter\Ohhh a quoted directory name!\and other nonsense
md "ThisIsATest\Some Directories have Spaces\But this Shouldn't matter\Ohhh a quoted directory name!\and other nonsense"
del /s/e/x/y /nest THISISJUSTAPLACEHOLDER.NOTAREALFILENAME

This is what the output looks like:
Removing E:\a\
Removing E:\Directories\
Removing E:\directory\
Removing E:\have\
Removing E:\matter\Ohhh\
Removing E:\matter\
Removing E:\name!\and\
Removing E:\name!\
Removing E:\nonsense\
Removing E:\other\
Removing E:\quoted\
Removing E:\Shouldn't\
Removing E:\Spaces\But\
Removing E:\Spaces\
Removing E:\this\
Removing E:\ThisIsATest\Some\
Removing E:\ThisIsATest\Some Directories have Spaces\But this Shouldn't matter\Ohhh a quoted directory name!\and other nonsense\
Removing E:\ThisIsATest\Some Directories have Spaces\But this Shouldn't matter\Ohhh a quoted directory name!\
Removing E:\ThisIsATest\Some Directories have Spaces\But this Shouldn't matter\
Removing E:\ThisIsATest\Some Directories have Spaces\
Removing E:\ThisIsATest\
So nice and easy!
Try doing that with a CMD prompt!
 
Cybertool.jpg

Its uses are limited only by your own imagination.
 
Hi Charles,

I didn't expect a reply, but thanks for affirming that I'm not the only one who still loves the power of TCC in 2021! :)
And... I am more mature than you might gather from my nickname... not much... but ;)

del /s/e/x/y /nest THISISJUSTAPLACEHOLDER.NOTAREALFILENAME

I didn't mention one of the reasons I loved the above version is it gives very nice clean output of what directories have been removed.

Run this for a sample, anyplace on your drive. First two commands create a mess of empty directories.


This is what the output looks like:

So nice and easy!
Try doing that with a CMD prompt!

I would assume one would want to update the CDD extended list and not use "/Ne" .... but I guess everyone's milage would vary....
 
@Charles Dye - it might have been me with the DEL /a:d /s /e /x /y *

The /a:d is a nice additional safety feature. Thanks!
I strongly recommend against using the * wildcard, vs a fictitious file name.
Murphy wrote a law that covers this... That DEL * is just an accident waiting to happen! :-P

Oh ... and as an indication regarding Murphy's Law in my life...
I was surprised this morning when I typed cleandirs and got an Unknown command response.
Oh ya... I didn't add the alias to the startup :banghead: hehehehehe
 
For me, the best way to totally nuke a folder {AND all files in it}, is:
*del /a: /f /k /s /t /x /z /Nj /P /E %DIR%

Though I wrap this behind my own askyn.bat that forces a prompt to be answered affirmatively before invoking!
 
For me personally, I'll never choose a cygwin-dependent solution over cygwin-independent solution, if possible.

rmdir doesn't have options to not recurse junctions. Or as many options in general. I don't know what happens in that situation, and I don't want to. Seems dangerous compared to the devil i know.
 
I've used del /s /e /x /y con.* — knowing that Windows will not allow filenames to match a device name.

And I've seen others using something like del /a:d /s /e /x /y * on the theory that DEL deletes files, and no file will have the Directory attribute set. (Test with caution; I'm not certain of the syntax for that approach.)

Want to prevent the top-level directory from being removed? Switch to it with PUSHD before your DEL, and POPD out afterwards. You can't remove the current directory.
That would be me @Charles Dye - ev en if I am not as sexy as tom cruise LOL
 
For me personally, I'll never choose a cygwin-dependent solution over cygwin-independent solution, if possible.

rmdir doesn't have options to not recurse junctions. Or as many options in general. I don't know what happens in that situation, and I don't want to. Seems dangerous compared to the devil i know.
It's not an option. rmdir first tries to remove the object, and only if it fails - recurse.
And if Cygwin is your daily tool, it's more likely that you use itself over TCC for scripting a task.
If I write a batch job, I use either Cygwin or TCC, only mixing both, if a task is either cross-domain (TCC script to manage Cygwin installation) or there's simply NO way of doing the same task to the same effect in TCC.
Though, lately I lean more to powershell.
 
Back
Top
[FOX] Ultimate Translator
Translate