Ditching empty folders

Jul 12, 2008
286
0
Las Vegas, NV
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
 
Jun 3, 2008
115
1
Temecula, CA
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
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.
 
Jul 12, 2008
286
0
Las Vegas, NV
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
4,423
85
Albuquerque, NM
prospero.unm.edu
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
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
Jul 12, 2008
286
0
Las Vegas, NV
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
4,423
85
Albuquerque, NM
prospero.unm.edu
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
4,423
85
Albuquerque, NM
prospero.unm.edu
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.)
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
Similar threads
Thread starter Title Forum Replies Date
gentzel Directory stack empty when running TCEXIT? Support 9
Chen Touboul When i try to delete an empty folder i got "the dirctoy name is invalid" Support 3
M WAD "Pictures" directory is empty in TCC but not in CMD or Explorer Support 4
thorntonpg sync /S /F creating empty directories Support 5
T input accepts empty answer Support 5
D Directory stack empty Support 1
vefatica Empty .watch files saved Support 0
M Forums appear empty if I'm not logged in Support 2
A How to? Frozen session tab with "ERROR: The file is either empty or does not contain the valid choices." Support 19
C How to? List empty folders Support 21
L WAD File-popup Window nearly empty Support 6
T dir /h error in empty directory Support 22
C MOVE making empty destinatation sub-folders Support 10
D LIST command wierdness with empty Unicode file Support 1
vefatica DO variable left with empty value Support 0
rconn Installer leaves directory empty Support 7
Charles Dye Create empty registry value? Support 5
T How to? ZIP/7ZIP @listfile with folders Support 2
D Fixed @Folders[] Support 2
B How to? Pre-set _tcfolder on startup when Folders is set Auto-Hide Support 6
D Folders pane display problem when starting Support 4
D Folders pane display problem after rename Support 0
vefatica Strange folders Support 1
E TCC dir /s command not showing all folders Support 6
D sync navigation between Folders List panel and the Tabs console Support 11
CWBillow Deleting folders Support 4
A Inverse of CDD /t c:\ (sync TCC currdir to Folders view)? Support 9
N Problem with Folders tab (not refreshing) Support 1
Ville Changing folders location from TCC prompt? Support 7

Similar threads