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).
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
*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.
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.)
Iff %Root == "" Then
@EchoErr Error: Missing name of directory to be processed.
Iff NOT EXIST %Root Then
@EchoErr Error: A directory named %Root does not exist!
Iff NOT IsDir %Root Then
@EchoErr Error: File-system object %Root is not a directory!
GoSub ProcessDirectory %Root
Gosub RemoveDirectory %Root
For /D %ThisDir in ("%@UnQuoteS[%Directory]\*") Do (
Gosub ProcessDirectory "%ThisDir"
Gosub RemoveDirectory "%ThisDir"
If "%NotEmpty" == "" ^
If %@Files["%Directory\*",-D] == 0 ^
Iff "%Empty" == "Y" Then
Attrib -R /D %Directory >NUL:
RD %Directory >NUL:
Iff %_? != 0 Then
@EchoErr Note: Failed to remove apparently empty directory %Directory
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.
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?)