Batch file path


P

Paul

bud-- said:
I am trying to write a batch program to delete a file that has
"Documents and Settings" in the path. It does not work.

Trouble shooting from the "Command Prompt" ('DOS screen'):
the current directory is C:\Documents and Settings

========================
dir c:\p* [wild card *]
returns
Volume...
Volume Serial Number...
Directory of c:\
... <DIR> Program Files
=======================
dir c:\program*
returns
Volume...
Volume Serial Number...
Directory of c:\
... <DIR> Program Files

----------------------
both are as expected

=======================
dir c:\program * [space added m *]
returns
Volume...
Volume Serial Number...
Directory of c:\
File Not Found

Directory of C:\Documents and Settings [the current directory]
[list of files in that directory]

---------------------------
this is not as expected (compared to DOS) -----
directory of c:\ should have found "...<DIR> Program Files"
and "Directory of C:\Documents and Settings" should not appear

=====================
dir c:\programf* [omit the space]
returns
Volume...
Volume Serial Number...
Directory of c:\
File Not Found

---------------------------
again what I expect

==================================
dir c:\program%20*
dir c:\program%20f*
[I have seen %20 used as a space - ASCII 20 hex is space]

both same as above - File Not Found

======================
The command prompt does not seem to function when there is a space in
the path.
Any ideas on how to handle a path that requires a space?


Running XP Professional SP3 Build 2600

Have you considered some quote marks ? That's the kind of
thing that works in other OSes. And in some OSes, the single
quote character has a different effect than the double quote
character. (You end up mixing them, for different purposes.)

dir "C:\Documents and Settings"

For each scripting environment, you have to learn about
what can be used for quoting, what can be used to escape
the quote character, so it can be used for normal things.
And depending on the environment, how many "layers" of
escape characters are needed, so that at least one survives
until it hits the shell interpreter.

Example here, of someone using the terminology of scripting trivia...

http://www.robvanderwoude.com/escapechars.php

You just try the stuff, until it works.

http://www.computerhope.com/forum/index.php/topic,34613.0.html

Try a Google search like this, for more tutorials:

msdos escape quote characters

HTH,
Paul
 
Ad

Advertisements

B

bud--

I am trying to write a batch program to delete a file that has
"Documents and Settings" in the path. It does not work.

Trouble shooting from the "Command Prompt" ('DOS screen'):
the current directory is C:\Documents and Settings

========================
dir c:\p* [wild card *]
returns
Volume...
Volume Serial Number...
Directory of c:\
.... <DIR> Program Files
=======================
dir c:\program*
returns
Volume...
Volume Serial Number...
Directory of c:\
.... <DIR> Program Files

----------------------
both are as expected

=======================
dir c:\program * [space added m *]
returns
Volume...
Volume Serial Number...
Directory of c:\
File Not Found

Directory of C:\Documents and Settings [the current directory]
[list of files in that directory]

---------------------------
this is not as expected (compared to DOS) -----
directory of c:\ should have found "...<DIR> Program Files"
and "Directory of C:\Documents and Settings" should not appear

=====================
dir c:\programf* [omit the space]
returns
Volume...
Volume Serial Number...
Directory of c:\
File Not Found

---------------------------
again what I expect

==================================
dir c:\program%20*
dir c:\program%20f*
[I have seen %20 used as a space - ASCII 20 hex is space]

both same as above - File Not Found

======================
The command prompt does not seem to function when there is a space in
the path.
Any ideas on how to handle a path that requires a space?


Running XP Professional SP3 Build 2600
 
B

bud--

Batch commandcs (BAT and CMD) are not programs, they are scripts.

When working with long file names with spaces one must enter the path in
quotation maks as in...

"C:\Documents and Settings\Lipman\My Documents\"

You must be explicit in your calls or the OS assumes the implicit which
is the "present" directory you are in.

You are both right, quotes work. Thanks.

I suppose the failure should have been obvious. You can put multiple
arguments on the command line, separated by spaces.
 
J

J. P. Gilliver (John)

David H. said:
From: "bud--" <[email protected]> []
I suppose the failure should have been obvious. You can put multiple
arguments on the command line, separated by spaces.

Exactly. The "space" is a delimter. Therefore if a path has a space
within it will be misinterpreted. Using qotation marks markes trhe
string, including any/all spaces, as one argument past on to the routine.
That's "passed on", not "past on". (Pedantic I know, but in this sort of
context, a valid point I think!)
 
Ad

Advertisements

D

David H. Lipman

From: "J. P. Gilliver (John) said:
David H. Lipman said:
From: "bud--" <[email protected]> []
I suppose the failure should have been obvious. You can put multiple arguments on the
command line, separated by spaces.

Exactly. The "space" is a delimter. Therefore if a path has a space within it will be
misinterpreted. Using qotation marks markes trhe string, including any/all spaces, as
one argument past on to the routine.
That's "passed on", not "past on". (Pedantic I know, but in this sort of context, a
valid point I think!)
--

LOL
And you are so write.

ROFLOL
Just kidding.
And you are so Right ;-)
 

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