Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD del behaves inconsistenly#

Jun
223
0
I was thinking about replacing GNUWin32 rm with del, but del /s behaves inconsistently; consider:

x> dir /b1 /s
x\ultimo <DIR>
x\zz <DIR>
x\zz\ultimo

: This one removes (expected) only the root ultimo directory but leaves any ultimo file (or directory) in every subdirectory in place
x> del /eklqxyz /s ultimo
x> dir /b1 /s
x\zz <DIR>
x\zz\ultimo

: This one removes (unexpectedly) every ultimo file (or directory) in any subdirectory
x> del /eklqxyz /s ultimo
x> dir /b1 /s
%

: This one removes both, any ultimo file (or directory) in any subdirectory and every root level ultimo directory (a path was specified which is not found in the base directory)
x> del /eklqxyz nonsense ultimo

In my opinion, either the first command should also delete EVERY ultimo file (or directory) - a change for the worse -, or the second command should LEAVE any ultimo file (or directory) below the current level untouched - the way to go.
 
Addendum: cmd would only delete the zz\ultimo file and leave the root ultimo directory untouched. So, this is not a compatibility issue anyway.
 
Your report fails to mention the platform as well as the command processor version and build.This is most important for a BUG report!

Your report of original content (i.e., names of files and directories) is obviously not created by the internal DIR command of TCC as shown, because 1/ it would report full paths for all entries (not a relative path), 2/ would not include the string <DIR>. The only way you could tell whether a line reports a file or a directory is if you use colorization (which is what I do for this very reason). The command below reports D or F for directories and files, respectively, followed by the full path (LFN) of each:
pdir /(@if[%%@attrib[*,d] EQC 1,D,F] fpn) /a: /s /ogne
It observes PDIR colorization, too. It would prove better information in the Forum about original directory content.

The DEL command has a simple control over deleting only files, only directories, or both: /A:-D, /A:D, and /A:, respectively. This works esp. well when you have a list of directory entry names, e.g., ultimo in your example above. The /X option would delete any directory which is empty after deleting the named entries. The command
del /eklqxyz /s ultimo
should delete every file named ultimo in the current directory and its subdirectories, but it should not delete any directories regardless of their name, except those that are, or become during the operation of the command, empty, Note that this is the same command listed both as the first and second example in your report, reporting different results. Executing the DEL command the first time may create a new context in which executing the identical command finds more things to delete.
--
HTH, Steve
 
After all that, I'm really not clear on what you're trying to do. If you want to delete only files named "Ultimo", you can create a wildcard pattern which matches only that name:

Code:
del /s /x /z ultim[o]

If you want to remove a subdirectory named "Ultimo", I'd suggest RD /S instead. RD expects, specifically, a directory name. (It's also quicker to type.)
 
This is a command which will remove all subdirectory trees of the current directory which contain no files:
*del/qyxs/net/a:d .
I make it the value of an alias for quick (and unthinking) access.
 
@Steve

[ben@pcben:3816:1 2] D:\temp\down\xx> md ultimo zz
[ben@pcben:3816:1 0] D:\temp\down\xx> > ultimo\nope
[ben@pcben:3816:1 0] D:\temp\down\xx> > zz\nope
[ben@pcben:3816:1 0] D:\temp\down\xx> > zz\ultimo

[ben@pcben:3816:1 0] D:\temp\down\xx> dir /a /ogen /h /ne /bs
D:\temp\down\xx\ultimo
D:\temp\down\xx\zz
D:\temp\down\xx\ultimo\nope
D:\temp\down\xx\zz\nope
D:\temp\down\xx\zz\ultimo

[ben@pcben:3816:1 0] D:\temp\down\xx> del /klxyz /s ultimo*
TCC: (Sys) There are no more files.
"D:\temp\down\xx\ultimo*"
TCC: (Sys) The system cannot find the file specified.
"D:\temp\down\xx\ultimo\ultimo*"
TCC: (Sys) The directory is not empty. // An attempt is made to delete the directory (/x)
"D:\temp\down\xx\ultimo"
Deleting D:\temp\down\xx\zz\ultimo
TCC: (Sys) The directory is not empty.
"D:\temp\down\xx\zz"
1 file deleted

[ben@pcben:3816:1 0] D:\temp\down\xx> dir /a /ogen /h /ne /bs
D:\temp\down\xx\ultimo
D:\temp\down\xx\zz
D:\temp\down\xx\ultimo\nope
D:\temp\down\xx\zz\nope

[ben@pcben:3816:1 0] D:\temp\down\xx> del /klxyz /s ultimo
Deleting D:\temp\down\xx\ultimo\nope // Not using a wildcard, ...
Removing D:\temp\down\xx\ultimo\ // ... ultimo is getting deleted as it's empty now (/x)
1 file deleted

[ben@pcben:3816:1 0] D:\temp\down\xx> dir /a /ogen /h /ne /bs
D:\temp\down\xx\zz
D:\temp\down\xx\zz\nope

I.e. the removal of ultimo only happened due to the usage of /x in conjunction with /s. This effectively makes del unusable for removing directories... Ok, you might say WAD, and I might live with that, but this behavior introduces a problem: When would I use rmdir, and when del? The obvious answer is "use rmdir with directories only, and del with files only", however this would
1) make it necessary for any script/command line action to differentiate between directories and files, which in turn
2) prevents you from using one command for both, directory and file deletion (rm -r is "agnostic" of this difference) - I know, you might write a script for that...

But, how about adding a switch (like e.g. /g) that mimics rm's behavior?
 
I do have an alias which will unconditionally remove a directory tree:
exs is an alias : *del/qxyzs/nejt
It removes the directory specified and its subdirectories.
Note that the combined options end with s - in that position there is no ambiguity. BTW, option /1 in /b1 is superfluous - /1 is the default.

I will examine your detail report a little later.
 
WAD.

DEL is the wrong tool to use if you want to delete subdirectories -- use RD. DEL only deletes directories in two cases:
  1. A subdirectory is empty and you specified /S /X
  2. You specified the root directory (and no filename), and used /S and /X
This is 20+ year old behavior, and definitely will not be changed -- it would break (catastrophically) a few zillion batch files and aliases, while providing no discernible benefit.

Your desired syntax requires TCC to automagically know whether you're referring to directories or files (or far, far worse, both).
 

Similar threads

Back
Top