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

MOVE making empty destinatation sub-folders

Discussion in 'Support' started by Charles G, Mar 23, 2012.

  1. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,018
    Likes Received:
    0
    <prompt> MOVE /n:e /s *.ext Dest\

    makes empty subfolders under Dest\, is there a way to stop this or is this a suggestion that occured to me?
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,856
    Likes Received:
    83
    WAD -- MOVE can't tell whether there's additional subdirectories until it copies (or creates) the first one and then recurses through the others.

    The only way around this would be to make MOVE a multipass operation, which would be (1) much slower, and (2) much more complicated. The current one or two complaints a year don't warrant a major rewrite to make things slower (which would generate a lot more complaints).
     
  3. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Charles, attached is zip file that contains a program that I wrote years ago in C++ that I just call RED (Remove Empty Directories). You are free to use it, and if you want the source for whatever reason(s) I would be glad to let you have it (assuming I can find it; as I said I wrote it more than 10 years ago and I've lost a not-completely backed-up hard drive in the intervening years). If you want, you could easily make a two-line batch file that is aliased to the name "Move" that does the "standard" TCC move (*move) followed by executing this program. - Dan
     

    Attached Files:

    • RED.zip
      File size:
      35.5 KB
      Views:
      0
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    It's been awhile, but I believe you can also remove empty subdirectories with a command like:

    Code:
    del /s /e /x /y c:\targetdir\con.*
    
    (That won't delete any actual files; you can't have any files matching CON.* .)
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    The command
    *del /q /y /x /s /net /a:d TARGET
    deletes all subdirectory trees of TARGET that do not contain any files. I've been using it for years. I doubt it to be slower than Dan's program. You could combine this command with MOVE in an alias in the manner Dan suggested.

    When I copy a directory tree from an FTP server, I always follow it with this command - the /F option of COPY, which on a local operation does not create an empty directory, is not functional for FTP copies for the same reason Rex reported above for MOVE.
     
  6. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    And while it's not all that interesting given the above, I decided while I was watching TV to make a .btm file to match the C++ program whose source I can no longer find and that offers complete "transparency" regarding what is taking place. It's only (rather small) advantages to Steve's approach (above) is that it handles empty directories that have their read-only attribute set and, somewhat more importantly, it will report a failure if there is a failure (the only kind of failure that is really possible given that it takes the read-only attributes off of all of the directories that are eligible for deletion is failure because some process still has a "handle" on a directory). (I will add that as I have mentioned before in these forums I am somewhat obsessive when it comes to error detection and reporting.)
    Code:
      @Echo Off
      SetLocal
      Set Root="%@UnQuoteS[%1]"
      Iff %Root == "" Then
          @EchoErr Error: Missing name of directory to be processed.
          EndLocal
          Quit 8
      EndIff
      Iff NOT EXIST %Root Then
          @EchoErr Error: A directory named %Root does not exist!
          EndLocal
          Quit 16
      EndIff
      Iff NOT IsDir %Root Then
          @EchoErr Error: File-system object %Root is not a directory!
          EndLocal
          Quit 32
      EndIff
      GoSub ProcessDirectory %Root
      Gosub RemoveDirectory  %Root
      EndLocal
      Quit 0
    :ProcessDirectory [Directory]
      Set NotEmpty=
      For /D %ThisDir in ("%@UnQuoteS[%Directory]\*") Do (
          Set Empty=Y
          Gosub ProcessDirectory "%ThisDir"
          Gosub RemoveDirectory  "%ThisDir"
      )
      Set Empty=
      If "%NotEmpty" == "" ^
          If %@Files["%Directory\*",-D] == 0 ^
            Set Empty=Y
      Return
    :RemoveDirectory [Directory]
      Iff "%Empty" == "Y" Then
          Attrib -R /D %Directory >NUL:
          RD %Directory >NUL:
          Iff %_? != 0 Then
            @EchoErr Note: Failed to remove apparently empty directory %Directory
            Set NotEmpty=Y
          EndIff
      Else
          Set NotEmpty=Y
      EndIff   
      Return
     
    
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    AFAIK my command will report failure to delete a directory which is eligible for deletion; /ne justs stops reporting that there is nothing more to delete when a directory is empty. Usually I follow its use with a DIR command reporting all files and directories remaining in TARGET, which would show up any remaining empty directories anyway.
     
  8. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Steve, that's good to know; the above was just re-doing the (now lost) C++ program as I remembered it as a batch file. As I've mentioned quite a few times previously in this forum, it is my goal to replace C++ programs by batch files whenever possible, and it's generally pretty much always possible given the "powers" and capabilities of TCC. And you are using some options on the "del" command that I wasn't aware of; but that's not too surprising given both my bad memory and the almost overabundance of options/capabilities that TCC has. - Dan

    (By the way, what does the acronym "AFAIK" stand for?)
     
  9. thedave

    Joined:
    Nov 13, 2008
    Messages:
    253
    Likes Received:
    2
    AFAIK is "As far as I know", at least AFAIK.
     
  10. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Dear The Dave:
    That is what I intended it to mean.

    Dan:
    Google is your friend when an acronym is not familiar. Even Rex' favorite, DWIM is listed as he uses it.
     
  11. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Guys, not even a word! Simply :)!
     

Share This Page