1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Ditching empty folders

Discussion in 'Support' started by CWBillow, Oct 14, 2008.

  1. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    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
     
  2. MickeyF

    Joined:
    Jun 3, 2008
    Messages:
    74
    Likes Received:
    0
    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.
     
  3. dbartt

    Joined:
    May 29, 2008
    Messages:
    36
    Likes Received:
    0
    CWBillow wrote:

    Try del /a:d /n /ne /s /y /x path
    Remove the /n option when testing looks like it does what you want.
     
  4. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Fabulous. Thanks.

    Regards,
    Chuck Billow
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Charles, would that be any better than just switching to the topmost directory, and executing the command from there?

    Regards,
    Chuck Billow
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    That's exactly what I'm doing.
     
  8. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    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...?
     
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    That's fine. TCC can't remove the current working directory.
     
  10. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Ah...so then the pushd is needed when the command is issued to a directory other than the current one?
     
  11. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Charles, I certainly wouldn't want my top directory removed! I Gotcha now.

    Thanks,
    Chuck Billow
     

Share This Page