Order of DIR options and file names

May 30, 2008
235
2
Does the DIR command allow options to be placed after the file/directory name specifications? It does seem to cause some problems when you put options last at least.


In the example below the /b switch is only applied to dir2.


C:\temp\test>dir dir1 dir2 /B

Volume in drive C is Local Disk Serial number is 60cd:fa66
Directory of C:\temp\test\dir1\*

20.08.2008 9:42 <DIR> .
20.08.2008 9:42 <DIR> ..
20.08.2008 9:42 13 test1
20.08.2008 9:42 13 test2
20.08.2008 9:42 13 test3
39 bytes in 3 files and 2 dirs 12 288 bytes allocated
8 406 994 944 bytes free
name1
name2
name3


But when you put it first it is applied to both dir1 and dir2.


C:\temp\test>dir /B dir1 dir2
test1
test2
test3
name1
name2
name3


When you read the help entry for DIR it seems to suggest you should put all options before all file names. Sometimes, in batch files and aliases, it would be easier if you could put the options last though.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
nikbackm wrote:
| Does the DIR command allow options to be placed after the
| file/directory name specifications? It does seem to cause some
| problems when you put options last at least.
| ...
| When you read the help entry for DIR it seems to suggest you should
| put all options before all file names. Sometimes, in batch files and
| aliases, it would be easier if you could put the options last though.

Less convenient or not, in all descendants of COMMAND.COM (CMD.EXE,
4DOS.COM, 4NT.EXE, TCMD32.EXE, TCC.EXE, etc.) the well documented general
rule for all commands is that options must precede parameters. In some
commands some options may be placed between paramters; they first parameter
they will affect is either the one immediately preceeding it or immediately
following it, depending on the command and option, and all parameters
thereafter, until superceded by a converse option, if any. The /B and /A
options of COPY are the clearly docuented example of the special use.
Another documented rule, applicable to JPsoft command processors only, is
that the "range" options must be first.

Another pair of rules that is very rarely obeyed:
- each option must have its own switch character (slash / by default)
- each option must be separated by white space from all other command
elements, including other options.

In many - actually most - instances the command processor accepts incorrect
syntax and does what I mean (DWIM). Observing the option separation rules is
usually not required. Using the /N option at the end of the command line to
show what the results of one of the file manipulation commands would be but
Not performing the command works fine, and is particularly useful in
interactive work - I can test the command by putting /N at the end, and if
it reports the desired action, I can recall it, delete the last two
characters, and do it by just 3 keystrokes.

However, unambiguous interpretation sometimes requires strict observation of
the rules, esp. the most basic one (options before parameters). I suspect
the DIR command's behavior you reported is due to the option letter being
one of the letters A and B, with require special handling in the COPY
command. Undoubtedly this special processing is used in file manipulation
commands other than COPY where it is harmless - if you had obeyed the syntax
rules.
--
Steve
 

rconn

Administrator
Staff member
May 14, 2008
12,312
147
nikbackm wrote:

> Does the DIR command allow options to be placed after the file/directory
> name specifications? It does seem to cause some problems when you put
> options last at least.

Only as a special case when you have a single argument. Since DIR
supports multiple arguments, options apply to the following argument(s),
which allows you to use different options for each argument.

Rex Conn
JP Software
 
Similar threads
Thread starter Title Forum Replies Date
Dick Johnson How to force TCC to count in proper numerical order Support 6
Steve Pitts REXX support - order of selection Support 2
fpefpe command order Support 2
C order popup windows as /o:gen ? Support 1
rps Documentation "Select" command switch order incorrect Support 4
fpefpe Documentation Search order Support 2
H touch sensitive to order of options Support 2
vefatica Order of evaluation? Support 3
D Copy /n option order Support 5
A Rename Files in Chronological Order? Support 5
D Changed order of folder names in @file Support 4
S Startup/Shutdown order of events for TCC Support 6
E Fixed Bug with DIR /Z displaying descriptions Support 8
J Paths shown in DIR /B Support 2
K Fixed Prompt display will be shifted after use dir to display a filename with Chinese. (v25.00.28 x64) Support 18
Jesse Heines How to? How to display picture creation date with dir command Support 6
vefatica WAD DIR.BTM? Support 11
DrusTheAxe DIR reports meaningless SYMLINK information Support 14
C show file description? with dir? Support 8
vefatica DIR /F and streams? Support 7
rps Multi-column DIR /v not displaying all files. Support 5
R How to? Dir specific file search patterns with spaces in the pathnames? Support 6
rps Dir /Nfv -> Alt-F2 Support 2
rps @FILESIZE[....,a] allocated size not matching Dir results Support 8
A TCMD - Dir Command puts out blank lines? Support 16
S Problems with dir command in the debugger Support 5
M TCC incorrect dir output since Windows 1803 Support 6
x13 Problem listing repository files using DIR http(s)://... Support 8
cxxl dir /s works in mysterious ways :( Support 4
vefatica Help nit (FFIND and DIR with /S) Support 0
N Fixed Strange dir behavior Support 6
JohnQSmith Weird DIR output (missing lines) Support 1
C 7zip with date range .vs. filelist created with dir and daterange Support 0
D Towards shared (dir-)history lists Support 3
vefatica WAD DIR /HL still gets names wrong Support 16
vefatica DIR /S /HL? Support 4
H Fixed DIR /G returns wrong sizes Support 2
nickles WAD dir.htm Support 2
vefatica DO dir in /s /a:+d /d"g:\" * ( ... ) Support 26
vefatica DIR \\.\...? Support 4
M Fixed DIR /S /B1 ignores "/S" Support 5
C tcmd.ini not loading from program dir? Support 5
D Fixed Dir /Nm:n has changed Support 1
rps How to? dir /s unexpected results Support 10
vefatica Update to current install dir? Support 8
cgunhouse Problem with "dir /=" Support 4
T dir /h error in empty directory Support 22
P WAD TC 15.0.1.58 x64 crasches with a simple dir command Support 18
CWBillow dir /4 strange Support 2
samintz WAD DIR /B1 and /X Support 2

Similar threads