Jump to content


Photo
- - - - -

Batch file w/ spaces


  • Please log in to reply
5 replies to this topic

#1 O(V)eGA_l2el)

O(V)eGA_l2el)

    Total Nerd

  • Folding Member
  • 3005 posts
  • Gender:Male

Posted 28 April 2007 - 05:48 PM

I have noticed one of my batch files contains a directory name with a space and does not execute correctly. Although, other batch files containing names with spaces execute with no problems. What am I overlooking in this particular batch file. Should I use quotation marks, a tilde, or some other character to signify a space within filenames?

Syntax Example:

@echo off
echo Starting fileone...
cd H:\Directory One\Subdirectory\fileonedirectory
start fileone.exe

#2 Nemo

Nemo

    Will Fold 4 Food

  • Honorary Staff
  • PipPipPipPipPipPip
  • 7228 posts
  • Gender:Male
  • Location:Franklin, TN

Posted 28 April 2007 - 07:37 PM

I have noticed one of my batch files contains a directory name with a space and does not execute correctly. Although, other batch files containing names with spaces execute with no problems. What am I overlooking in this particular batch file. Should I use quotation marks, a tilde, or some other character to signify a space within filenames?

Syntax Example:

@echo off
echo Starting fileone...
cd H:\Directory One\Subdirectory\fileonedirectory
start fileone.exe

Try enclosing the directory name in quotes like this: cd "H:\Directory One\Subdirectory\fileonedirectory"

Intel Core 2 Quad Q9550 2.83GHz / ASUS P5Q Deluxe / Patriot Extreme Performance 2GB PC2-9600 DDR2-1200MHz / 2x Seagate ST3160827AS 160GB RAID 1 / Seagate ST31000340AS 1TB
Corsair TX750W / Sapphire HD 5870 1GB GDDR5 / SilverStone TJ05 / Scythe Zipang 140mm CPU Cooler / ASUS VH202T-P 20" widescreen monitor (x2) / XP Pro SP 3
"however, i cannot claim to be such a fish as i am not a fish at all..." - hardnrg,Jul 4 2005, 02:49 PM
 

Posted Image

Posted Image

Follow OCC on Posted Image
Subscribe to the OCC Newsletter

Lucky Mudder Race 2013


#3 O(V)eGA_l2el)

O(V)eGA_l2el)

    Total Nerd

  • Folding Member
  • 3005 posts
  • Gender:Male

Posted 29 April 2007 - 05:13 AM

Try enclosing the directory name in quotes like this: cd "H:\Directory One\Subdirectory\fileonedirectory"


Enclosing that line does not work; the results remain the same (can not find fileone.exe).

#4 Nemo

Nemo

    Will Fold 4 Food

  • Honorary Staff
  • PipPipPipPipPipPip
  • 7228 posts
  • Gender:Male
  • Location:Franklin, TN

Posted 29 April 2007 - 05:16 AM

What about: start "H:\Directory One\Subdirectory\fileonedirectory\fileone.exe"

Intel Core 2 Quad Q9550 2.83GHz / ASUS P5Q Deluxe / Patriot Extreme Performance 2GB PC2-9600 DDR2-1200MHz / 2x Seagate ST3160827AS 160GB RAID 1 / Seagate ST31000340AS 1TB
Corsair TX750W / Sapphire HD 5870 1GB GDDR5 / SilverStone TJ05 / Scythe Zipang 140mm CPU Cooler / ASUS VH202T-P 20" widescreen monitor (x2) / XP Pro SP 3
"however, i cannot claim to be such a fish as i am not a fish at all..." - hardnrg,Jul 4 2005, 02:49 PM
 

Posted Image

Posted Image

Follow OCC on Posted Image
Subscribe to the OCC Newsletter

Lucky Mudder Race 2013


#5 markiemrboo

markiemrboo

    BSD Fiend

  • Members
  • PipPipPipPipPipPip
  • 5955 posts
  • Gender:Male
  • Location:Gt Yarmouth, UK

Posted 29 April 2007 - 05:58 AM

Perhaps a silly question, but are you sure you have the path right? I think enclosing in "'s should actually work...
( Intel C2Q9300 + Scythe Zipang (400 x 7.5 = 3GHz @ 1.3v) ) ( Gigabyte GA-P35C-DS3R v2.1 ) ( 2 x 2GB OCZ OCZ2N800SR4GK PC2-6400 (400 x 5-5-5-15 @ 2.1v) ) ( Sapphire 4890 OC 1GB ) ( 4 x 1TB Samsung F1, 1 x 500GB Samsung T ) ( Pioneer DVR-109XL ) ( X-fi XtremeMusic ) ( Corsair HX 520 ) ( Enermax Pandora CA-3030 ) ( 2 x Benq G2400W ) ( Cherry CyMotion Expert ) ( Windows Vista Ultimate x64 SP1 )

Posted Image

#6 Kamikaze_Badger

Kamikaze_Badger

    (⌐■_■)

  • Members
  • PipPipPipPipPipPip
  • 8337 posts
  • Gender:Male
  • Location:Somewhere

Posted 06 May 2007 - 07:31 PM

According to the CD help documentation:

CHDIR command does not treat spaces as deliminiters [...] so it is possible to CD into a directory with a space.

So chances are you've got the directory wrong, or you're not CDing correctly. Ah heck, I'll quote it:

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Evil Lion>help cd
Displays the name of or changes the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]

.. Specifies that you want to change to the parent directory.

Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.

Use the /D switch to change current drive in addition to changing current
directory for a drive.

If Command Extensions are enabled CHDIR changes as follows:

The current directory string is converted to use the same case as
the on disk names. So CD C:\TEMP would actually set the current
directory to C:\Temp if that is the case on disk.

CHDIR command does not treat spaces as delimiters, so it is possible to
CD into a subdirectory name that contains a space without surrounding
the name with quotes. For example:

cd \winnt\profiles\username\programs\start menu

is the same as:

cd "\winnt\profiles\username\programs\start menu"

which is what you would have to type if extensions were disabled.


So you should have this, methinks:

@echo off
echo Starting fileone...
cd /d H:\Directory One\Subdirectory\fileonedirectory
start fileone.exe

Is my Razer Diamondback retro yet?
s

Graciously recommended from KB, is some muffricken Christian death metal. It is a must hear, it pushes envelopes, explores new ground. Words can't describe just now incredibly awesome this is. Cue the alter smashing, bench flipping, and bible reading while thrashing away at guitars and drums.

I witnessed regional Special Olympics and Challenge Day; there's far more intellect there than there is in internet arguments.