Ditching empty folders

#1
is there a way to, starting in the Documents folder (Vista), say "OK start here and go all the way through all the folders and sub folders, deleting any folders if they are empty"?

Of course, if Folder A contains folder 2, and Folder 2 is empty, then it will delete Folder 2 but not Folder A, unless I ran the process again, assuming there is such a process.

Is there any such command or process that might do this?

Regards,
Chuck Billow
 
#2
This question comes up periodically. The method I use is to use the command "del /szxkqey ThisIsAFilenameThatWillNotExist" (or whatever name you want to use, that you know will not exist). That cleans up all of the empty subdirectories. Oh, and to use proper syntax, the "/szxkqey" should really be split into separate switches - "/s /z /x /k /q /e /y" but at least with the old 4NT version 6 that I'm using, it still works fine without splitting them.
 
May 29, 2008
36
0
#3
CWBillow wrote:

> is there a way to, starting in the Documents folder (Vista), say "OK start here and go all the way through all the folders and sub folders, deleting any folders if they are empty"?
>
> Of course, if Folder A contains folder 2, and Folder 2 is empty, then it will delete Folder 2 but not Folder A, unless I ran the process again, assuming there is such a process.
>
> Is there any such command or process that might do this?
>
> Regards,
> Chuck Billow
>
>
>
>
Try del /a:d /n /ne /s /y /x path
Remove the /n option when testing looks like it does what you want.
 
#4
This question comes up periodically. The method I use is to use the command "del /szxkqey ThisIsAFilenameThatWillNotExist" (or whatever name you want to use, that you know will not exist). That cleans up all of the empty subdirectories. Oh, and to use proper syntax, the "/szxkqey" should really be split into separate switches - "/s /z /x /k /q /e /y" but at least with the old 4NT version 6 that I'm using, it still works fine without splitting them.
Fabulous. Thanks.

Regards,
Chuck Billow
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,502
46
Albuquerque, NM
prospero.unm.edu
#5
This question comes up periodically. The method I use is to use the command "del /szxkqey ThisIsAFilenameThatWillNotExist" (or whatever name you want to use, that you know will not exist). That cleans up all of the empty subdirectories. Oh, and to use proper syntax, the "/szxkqey" should really be split into separate switches - "/s /z /x /k /q /e /y" but at least with the old 4NT version 6 that I'm using, it still works fine without splitting them.
I use NUL.* as a filespec that cannot exist:

Code:
del /s /e /x /y /z d:\pathname\nul.*
If it's possible that there are no files at all in the directory, and you don't want the topmost directory itself to be removed, you can protect it by temporarily changing to it:

Code:
pushd d:\pathname
del /s /e /x /y /z nul.*
popd
 
#6
I use NUL.* as a filespec that cannot exist:

Code:
del /s /e /x /y /z d:\pathname\nul.*
If it's possible that there are no files at all in the directory, and you don't want the topmost directory itself to be removed, you can protect it by temporarily changing to it:

Code:
pushd d:\pathname
del /s /e /x /y /z nul.*
popd
Charles, would that be any better than just switching to the topmost directory, and executing the command from there?

Regards,
Chuck Billow
 
#8
That's exactly what I'm doing.
But then would I need to "protect" that directory? or would that one get deleted as well -- if it were empty?

'cause I just went into the topmost level, C:\Users\CWBillow\Documents, and ran the command

del /s /z /x /k /q /e /y ThisIsAFilenameThatWillNotExist

straight away, and it seemed to worked OK...?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,502
46
Albuquerque, NM
prospero.unm.edu
#9
But then would I need to "protect" that directory? or would that one get deleted as well -- if it were empty?

'cause I just went into the topmost level, C:\Users\CWBillow\Documents, and ran the command

del /s /z /x /k /q /e /y ThisIsAFilenameThatWillNotExist

straight away, and it seemed to worked OK...?
That's fine. TCC can't remove the current working directory.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,502
46
Albuquerque, NM
prospero.unm.edu
#11
Ah...so then the pushd is needed when the command is issued to a directory other than the current one?
The PUSHD just makes it easy to return to the previous directory; CDD would work as well.

(And the only reason I suggest changing to the topmost directory is to prevent it from being removed. If there's a single file in there anywhere, it won't be. And if you don't mind the topmost directory being removed if it contains no files, then again there's no need to change to it.)
 
#12
The PUSHD just makes it easy to return to the previous directory; CDD would work as well.

(And the only reason I suggest changing to the topmost directory is to prevent it from being removed. If there's a single file in there anywhere, it won't be. And if you don't mind the topmost directory being removed if it contains no files, then again there's no need to change to it.)
Charles, I certainly wouldn't want my top directory removed! I Gotcha now.

Thanks,
Chuck Billow