dir and del command in CMD.exe perform wildcard match on short filename

P

PiErre

(my pc is winxp-pro sp2 - C: is ntfs 12GB)
I tested both with and without cmd
extensions (cmd /E:ON and cmd /E:OFF): no change

I had many files old-* and an important file
o.log.some.other.extension.doc
in the same directory; I issued a simple command

del ol*

and the important file was erased too!

Is this by design?
Isn't this quite dangerous?
Is there a way of obtaining the wildcard match only on LONG filenames?


here is an detailed example


C:\zz>dir
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:23 <DIR> .
2007-01-17 11:23 <DIR> ..
2007-01-17 11:23 0 o.log
2007-01-17 11:23 26 o.log.gz
2 File(s) 26 bytes
2 Dir(s) 1,713,643,520 bytes free

C:\zz>dir ol*
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:23 26 o.log.gz
1 File(s) 26 bytes
0 Dir(s) 1,713,643,520 bytes free

C:\zz>dir /x
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:23 <DIR> .
2007-01-17 11:23 <DIR> ..
2007-01-17 11:23 0 o.log
2007-01-17 11:23 26 OLOG~1.GZ o.log.gz
2 File(s) 26 bytes
2 Dir(s) 1,713,643,520 bytes free

C:\zz>del ol*

C:\zz>dir
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:24 <DIR> .
2007-01-17 11:24 <DIR> ..
2007-01-17 11:23 0 o.log
1 File(s) 0 bytes
2 Dir(s) 1,713,643,520 bytes free

C:\zz>



bye,
PiErre
 
P

Pegasus \(MVP\)

PiErre said:
(my pc is winxp-pro sp2 - C: is ntfs 12GB)
I tested both with and without cmd
extensions (cmd /E:ON and cmd /E:OFF): no change

I had many files old-* and an important file
o.log.some.other.extension.doc
in the same directory; I issued a simple command

del ol*

and the important file was erased too!

Is this by design?
Isn't this quite dangerous?
Is there a way of obtaining the wildcard match only on LONG filenames?


here is an detailed example


C:\zz>dir
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:23 <DIR> .
2007-01-17 11:23 <DIR> ..
2007-01-17 11:23 0 o.log
2007-01-17 11:23 26 o.log.gz
2 File(s) 26 bytes
2 Dir(s) 1,713,643,520 bytes free

C:\zz>dir ol*
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:23 26 o.log.gz
1 File(s) 26 bytes
0 Dir(s) 1,713,643,520 bytes free

C:\zz>dir /x
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:23 <DIR> .
2007-01-17 11:23 <DIR> ..
2007-01-17 11:23 0 o.log
2007-01-17 11:23 26 OLOG~1.GZ o.log.gz
2 File(s) 26 bytes
2 Dir(s) 1,713,643,520 bytes free

C:\zz>del ol*

C:\zz>dir
Volume in drive C is xxxx
Volume Serial Number is zzzz-zzzz

Directory of C:\zz

2007-01-17 11:24 <DIR> .
2007-01-17 11:24 <DIR> ..
2007-01-17 11:23 0 o.log
1 File(s) 0 bytes
2 Dir(s) 1,713,643,520 bytes free

C:\zz>



bye,
PiErre

Run the command

dir c:\zz /x

You will then see that the 8.3 file name matches your
wild card. That's why you lost the file!
 
P

PiErre

Pegasus said:
Run the command

dir c:\zz /x

You will then see that the 8.3 file name matches your
wild card.
That's why you lost the file!

ehm, I though it was clear
from the subject of my post that I already
discovered that! (it was already present in a command I posted)
What concern me is the fact that the filematch is on
the short filenames and not on the long ones...
Why is it so?

I would say it was a precise
design choice, but I cannot see the reason behind it...

More important: is there a way to change
this odd behaviour of filematching mechanism
in cmd.exe?

TIA!
bye,
PiErre
 
A

AJR

Have not seen the original post - however "CMD" (contrary to many opinions)
is equivalent to the MS-DOS prompt which has never had "long filename"
capability - I would like to have a quarter for every instant of that fact
in publications.
 
W

Wesley Vogel

Command.com is 16-bit and cannot handle long names only 8.3 short names.

Cmd.exe is 32-bit and can handle long or short names.

Cmd.exe is the Windows Command Processor and was developed for NT.

You CANNOT use long file names with command.com, quotes or no quotes. At
least with the Chdir (Cd) command.

------
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.

C:\>cd C:\Documents and Settings\Wesley P. Vogel\Local Settings\Temp
Too many parameters - and

C:\>cd "C:\Documents and Settings\Wesley P. Vogel\Local Settings\Temp"
Parameter format not correct - "C:\Documents

C:\>cd C:\DOCUME~1\WESLEY~1~VOG\LOCALS~1\Temp

C:\DOCUME~1\WESLEY~1\LOCALS~1\TEMP>
------

Too many parameters
There are too many spaces in the command you are typing. Valid format is
8.3 names.

Parameter format not correct
You typed one or more parameters that do not have a valid format for this
command. Valid format is 8.3 names.

Cannot Use Spaces in MS-DOS Command Parameters
http://support.microsoft.com/kb/229880

Native MS-DOS Commands and the Space Character
http://support.microsoft.com/kb/166827

Amazingly enough, this command works in command.com:

md "A Directory With a Long Name"

You can use long file names with cmd.exe.

You have to use quotes with some commands with cmd.exe, especially if the
path contains a white space.

Try the following commands in cmd.exe and see what happens...

start "" "C:\Program Files\Internet Explorer\iexplore.exe"

start "C:\Program Files\Internet Explorer\iexplore.exe"

start C:\Program Files\Internet Explorer\iexplore.exe

start iexplore

<quote>
Remarks
Using multiple commands
* You can use multiple commands separated by the command separator && for
string, but you must enclose them in quotation marks (for example,
"command&&command&&command").

Processing quotation marks
If you specify /c or /k, cmd processes the remainder of string and quotation
marks are preserved only if all of the following conditions are met:

* You do not use /s.
* You use exactly one set of quotation marks.
* You do not use any special characters within the quotation marks (for
example: &<>( ) @ ^ |).
* You use one or more white-space characters within the quotation marks.
* The string within quotation marks is the name of an executable file.

If the previous conditions are not met, string is processed by examining the
first character to verify whether or not it is an opening quotation mark. If
the first character is an opening quotation mark, it is stripped along with
the closing quotation mark. Any text following the closing quotation marks
is preserved.

File and directory name completion correctly processes file names that
contain white space or special characters if you place quotation marks
around the matching path.

The following special characters require quotation marks: & < > [ ] { } ^ =
; ! ' + , ` ~ [white space]

If the information that you supply contains spaces, use quotation marks
around the text (for example, "Computer Name").
<quote>
from CMD...
Paste the following line into Start | Run and click OK...

hh ntcmds.chm::/cmd.htm

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top