Difference in behavior of RMDIR vs. CMD.EXE?

Jun 11, 2014
3
0
Hi there,

I've always believed and found that 4DOS/4NT/TCC have worked as per Microsoft's shells (COMMAND.COM then later CMD.EXE) where there is a corresponding command/option combination.

However, our production department just partially obliterated a server (deleting all files older than 30 days) and it seems they fell foul of a behaviour difference, which I'm trying to understand.

The production manager, as he is prone to do, Googled a problem: he wanted to delete all empty directories on the system over 30 days old. He found a one-line CMD.EXE script using FORFILES and which crucially used RMDIR.

FORFILES /p f:\ /S /D -30 /C "cmd /c IF @isdir == TRUE RMDIR /S /Q @path"

Now, he also Googled RMDIR and found sites commenting on the fact RMDIR won't delete directories with directories and indeed my later tests seemed to bear this out.

However, in practice running in TCC 16 without any aliases (he assures me I haven't been able to verify that yet) this did delete all directories older than 30 days irrespective of their containing files or not.

Right now I am trying to understand if my previous implicit assumption that TCC is 100% comparable to CMD.EXE where such comparability exists is plain wrong.

As a follow-up, does anyone have a suggestion as to how this requirement (delete empty directories older than 30 days) can be achieved safely?

Thanks.
 
I suggest something like (tested only partially):
Code:
ffind/s /a:d /b /[!d-30] * | for %d in ( @con: ) if %@files[/h,%@quote[%d]]==0 rmdir %@quote[%d]

- The %@quote[] function is useful (only) if you directory names contain spaces.
- TCC's RMDIR is in fact documented to remove files and subdirectories.
- You don't state exactly what you mean with "empty" ("no files" or "no files neither directories") and "older than 30 days" (does this concern the directory alone or also its subdirectories); you may have to write more complex logic.
- Compatibilty to CMD is an issue often discussed in the forum; sadly it cannot be 100% because of incompatibility between versions of CMD. See for example https://jpsoft.com/forums/threads/date-and-cmd-compatibility.5646/#post-33490, search for "compatibility" in the forum.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,491
90
Albuquerque, NM
prospero.unm.edu
The production manager, as he is prone to do, Googled a problem: he wanted to delete all empty directories on the system over 30 days old. He found a one-line CMD.EXE script using FORFILES and which crucially used RMDIR.

FORFILES /p f:\ /S /D -30 /C "cmd /c IF @isdir == TRUE RMDIR /S /Q @path"

Since your script is spawning CMD.EXE to do the removal, I don't really see how TCC's implementation matters...?
 
May 26, 2008
541
4
FORFILES is an external command, not to mention you're running CMD to do the directory removal. This has nothing to do with Take Command as far as I can tell.

I think the mistake is that the RMDIR (RD) command has /S on it. That's going to remove the directory whether or not it's empty.
 

samintz

Scott Mintz
May 20, 2008
1,511
18
Solon, OH, USA
Robin,

As Christian mentioned you weren't clear on what "empty" means. There are a number of ways to do this quite easily in TCC. You can use date ranges to specify only files and directories older than 30 days. You can use file exclusion ranges to select only directories or only files. You can also use FOR or DO to iterate just like FORFILES does.

To look at only top-level directories that do not contain any subdirectories or files older than 30 days:
Code:
DO d in /[!d-30] /a:d * (if %@files[/h "%d"] == 0 RD "%d")
 
Similar threads
Thread starter Title Forum Replies Date
jwiede Difference in "FOR /F" behavior (?) Support 1
S Inexplicable behavior difference in nearly identical shortcuts Support 6
E TCC/CMD difference Support 5
R Difference between TCC and CMD: variable names with hyphens Support 4
W Starting program for word to pdf conversion (difference cmd and tcc) Support 13
C Documentation difference between appdata and localappdata ? Support 6
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
Steve Pitts Difference in exection with and without START Support 24
S TCC 9.02 vs 4NT 8.02 difference - for %a COPY Support 6
H @XMLNODES - New behavior? Support 3
Jesse Heines Strange Line Wrapping Behavior Support 14
H Behavior change re piping a string to a Java program Support 1
Jay Sage Baffling Behavior With TPIPE Support 5
D Pasting Unicode data has different behavior on TCC and CMD Support 2
P "Set" command behavior - a bug? Support 3
P LOG command behavior Support 3
I Puzzling Behavior of TDRV and DEL Support 2
N Fixed Strange dir behavior Support 6
A Inconsistent @WINPOS // ACTIVATE /POS= behavior Support 0
P Strange mouse behavior with list Support 2
R Find in screen buffer - find next behavior Support 0
D v20 code page behavior changes Support 2
D Strange DO behavior with /O Support 5
Jay Sage Change in Behavior of Activate Command Support 4
deleyd Fixed Behavior different than CMD Support 1
D Fixed Change in behavior of variable expansion between 16 and 17 Support 3
D Unexpected behavior Support 8
D Bash-like Esc->Backspace behavior Support 4
C ZIP behavior Support 5
Charles Dye Odd behavior after using OPTION "Advanced" tab Support 2
C odd behavior of "dir" Support 0
M How to? Work around an unexpected and very inconvenient behavior of TCC... Support 26
A expected behavior of move /sx Support 14
M WAD A complaint regarding a very irritating TCC installation behavior... (Bug?) Support 4
Peter Bratton @ping behavior change Support 2
vefatica SHORTCUT behavior (Win7) Support 3
M A question about new behavior that’s a minor irritation… Support 16
M Strange behavior... Support 2
S MSGBOX - inconsistent behavior Support 1
vefatica @REGEX: behavior vs. documentation Support 2
vefatica Strange behavior reloading SHRALIAS sav files. Support 1
S Strange CHKDSK behavior Support 6
Fross Odd IF behavior Support 3
M (Somewhat unbelievable) Do While Behavior/Question Support 1
S RECYCLE /P - unexpected behavior Support 0
J Odd OPTION behavior Support 1
D How to? Skip removing directory (RMDIR) without error message Support 2
nickles WAD [Discrepancy] Have rmdir work like described in the docs Support 7
A mkdir and rmdir very slow Support 5
JohnQSmith RD / RMDIR Usage Support 5

Similar threads