Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file path

7 views
Skip to first unread message

bud--

unread,
May 17, 2013, 2:16:10 PM5/17/13
to
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

Paul

unread,
May 17, 2013, 2:14:23 PM5/17/13
to
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

David H. Lipman

unread,
May 17, 2013, 3:41:04 PM5/17/13
to
From: "bud--" <remove....@isp.com>
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.

--
Dave
Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk
http://www.pctipp.ch/downloads/dl/35905.asp

bud--

unread,
May 19, 2013, 11:28:38 AM5/19/13
to
On 5/17/2013 1:41 PM, David H. Lipman wrote:
> From: "bud--" <remove....@isp.com>
>>
>> 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
>
> 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.

David H. Lipman

unread,
May 19, 2013, 10:55:09 AM5/19/13
to
From: "bud--" <remove....@isp.com>
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.

J. P. Gilliver (John)

unread,
May 19, 2013, 3:21:25 PM5/19/13
to
In message <SNOdnZVU97xYegXM...@giganews.com>, David H.
Lipman <DLipman~nospam~@Verizon.Net> writes:
>From: "bud--" <remove....@isp.com>
[]
>> 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!)
--
J. P. Gilliver. UMRA: 1960/<1985 MB++G()AL-IS-Ch++(p)Ar@T+H+Sh0!:`)DNAf

You can't abdicate and eat it - attributed to Wallis Simpson, in Radio Times
14-20 January 2012.

David H. Lipman

unread,
May 19, 2013, 4:04:44 PM5/19/13
to
From: "J. P. Gilliver (John)" <G6...@soft255.demon.co.uk>

> In message <SNOdnZVU97xYegXM...@giganews.com>, David H. Lipman
> <DLipman~nospam~@Verizon.Net> writes:
>> From: "bud--" <remove....@isp.com>
> []
>>> 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 ;-)
0 new messages