Welcome!

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

SignUp Now!

Ditching empty folders

Jul
304
0
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
 
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.
 
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.
 
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
 
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
 
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
 
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...?
 
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.
 
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.)
 
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

Back
Top