MOVE making empty destinatation sub-folders

Apr 2, 2011
North Carolina, USA
<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?


Staff member
May 14, 2008
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).
May 24, 2010
Northlake, Il
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


    35.5 KB · Views: 80

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
It's been awhile, but I believe you can also remove empty subdirectories with a command like:

del /s /e /x /y c:\targetdir\con.*

(That won't delete any actual files; you can't have any files matching CON.* .)
May 20, 2008
Elkridge, MD, USA
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.
May 24, 2010
Northlake, Il
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.)
  @Echo Off
  Set Root="%@UnQuoteS[%1]"
  Iff %Root == "" Then
      @EchoErr Error: Missing name of directory to be processed.
      Quit 8
  Iff NOT EXIST %Root Then
      @EchoErr Error: A directory named %Root does not exist!
      Quit 16
  Iff NOT IsDir %Root Then
      @EchoErr Error: File-system object %Root is not a directory!
      Quit 32
  GoSub ProcessDirectory %Root
  Gosub RemoveDirectory  %Root
  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
: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
      Set NotEmpty=Y
May 20, 2008
Elkridge, MD, USA
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.
May 24, 2010
Northlake, Il
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?)
Similar threads
Thread starter Title Forum Replies Date
C question re: Move Support 3
samintz MOVE and Prompt on overwrite Support 3
M MOVE does not behaves like intended (on failure) Support 1
kb6ojs Make /G parameter persistent in COPY/MOVE command? Support 4
F Regexes in REN/MOVE/… commands seem to not work at all Support 3
T How to? Off screen move? Support 3
fpefpe Documentation copy/move using /c or /u Support 2
W Recursive move aborts early Support 2
C b21 MOVE /B Support 8
D How move cursor out of popup edit control after no match? Support 14
nickles Move takecommand.18.0.key location to installation directory Support 4
J junction copy/move handling Support 6
J WAD move /s regression from tcc15 Support 5
C move /F Support 4
vefatica MOVE anomaly Support 8
C Move /s sorce target Support 13
Stefano Piccardi b32 move /Q writes message Support 1
C How to? MOVE and handling out of space Support 2
Joe Caverly How to? Move Window Between Monitors Support 6
S How to? Move files older than one year Support 9
fpefpe move /g Support 4
C Move /MD not always working Support 1
C Move question with Encrypted file... Support 6
W /g option (%) on MOVE cmd appears broken TCC 14.03.57 x64 Support 8
G Fixed MOVE truncates files Support 9
thedave Move files, inherit permissions Support 14
A Discrepancy in handling of "can't copy or move file to itself" Support 4
A expected behavior of move /sx Support 14
S MOVE from FTP directory to another FTP directory - bug?? Support 2
J directory tree - move or copy Support 3
D MOVE Help typo Support 3
D Suggest Help mention /n no effect in move /n Dir1 Dir2 Support 0
D Move /v to DVD fails but files identical Support 4
S Conditionally MOVE/COPY files on the basis of size Support 1
S MOVE to different drive Support 3
Joe Caverly Move Buttons Between Tabbed Toolbars Support 2
S Another 4NT 8.02 vs TCC 9.02 diff - MOVE command Support 3
S MOVE command over FTP with 4NT 5.00U Support 0
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
T Formatting tools not working when making forum posts Support 2
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

Similar threads