Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command-Line: Long path names

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,312
US
I figured out long ago in dealing with long file names/path names with spaces that you can use them by putting " (double-quotes) around them. The problem I'm running into, though, is that it is not working when I try to do something via batch file.

A couple of examples: If I run something in "C:\Program Files" with double-quotes around the full path to the correct EXE, I'll get an error like this:

Code:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.

Another one I run into is this. If I do a simple interpreter command against a file with a long path name (space), I get this:

Code:
The filename, directory name, or volume label syntax is incorrect.

For what it is appearing, it's not accepting the double-quotes as a full path name. Any thoughts on what I need to do?

----------
Measurement is not management.
 
Can you post your batch file? What you have described is correct by putting the full path and EXE in double quotes so it seems strange why it is not working. Below is an example of how it should look:

Code:
@echo off
"C:\Program Files\Microsoft Office\Office11\WINWORD.EXE"

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Are you using any switches, as these have to go outside the quotes, e.g.

Code:
"C:\ProgramFiles\MyProgram\Client\myprog.exe" /Server=Dave /Seat=888 /User=Fred
Exit

Only the truly stupid believe they know everything.
Stu.. 2004
 
Ignore the fact Programfiles is one word, just a typo....

Only the truly stupid believe they know everything.
Stu.. 2004
 
As has been pointed out it should work with the double quotes.

You could of course also use the 8.3 shortened notation. So instead of Program Files it would be Progra~1.

Note the ~ character.

This notation is based on having path names only be 8 characters long and having a 3 character extension.

All longer path names are reduced to 6 characters plus the ~ character and a number. The number is used to differentiate between paths that have the same first 6 letters. such as Microsoft Internet Explorer, Microsoft Office etc...

Using TheLad's example
Code:
C:\Program Files\Microsoft Office\Office11\WINWORD.EXE

would look like:

Code:
C:\[red]Progra~1[/red]\[red]Micros~3[/red]\Office11\WINWORD.EXE

In my case Microsoft Office is Micros ~3 since I have other Microsoft products there including Microsoft.NET and Microsoft FrontPage.

In the case a file or folder name contains more than one "." period. the extension in the 8.3 notation will be the first 3 letters following the first period.

In the case of Microsoft .NET's folder it turns out to be Micros~2.NET

This avoids any problems with spaces, but can get cumbersome when dealing with many similarly named folders.
and with names that contains more than one period.

Using the /x switch for the dir command under windows will show you the 8.3 names for the files and folders in your current location.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
or just parse it into a variable like:

Code:
%TestPath% = "C:\Program Files\Western Digital\Data Lifeguard Tools\DataLifeguard.exe"

%TestPath%

works for me...

Ben

"If it works don't fix it! If it doesn't use a sledgehammer..."
 
Can you post your batch file?

No batch file, but what I am trying is duplicable in batch. An example of what I'm trying to do:

Code:
c:\windows\system32\cmd.exe /c "del" "D:\BACKUP\Delphi Done\MediaPlayer Demo2\mpdemo.exe" 

The filename, directory name, or volume label syntax is incorrect.

Command: c:\windows\system32\cmd.exe /c "C:\Program Files\Borland\Delphi 3\bin\dcc32.exe" "D:\BACKUP\Delphi Done\MediaPlayer Demo2\mp.pas" 

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

The command-interpreter is a requirement because of the possibility of commands like the first example.

----------
Measurement is not management.
 
For the first item, remove the quotes around the string:
Code:
c:\windows\system32\cmd.exe /c del "D:\BACKUP\Delphi Done\MediaPlayer Demo2\mpdemo.exe"
I didn't investigate any of the others.
 
You've got a program with a parser calling another program with a parser and the quotes are getting dropped somewhere.

You could try nesting quotes or double quoting to see if a pair can pass through. ie:

Command: c:\windows\system32\cmd.exe /c ""C:\Program Files\Borland\Delphi 3\bin\dcc32.exe"" ""D:\BACKUP\Delphi Done\MediaPlayer Demo2\mp.pas""

-or-

Command: c:\windows\system32\cmd.exe /c "'C:\Program Files\Borland\Delphi 3\bin\dcc32.exe'" "'D:\BACKUP\Delphi Done\MediaPlayer Demo2\mp.pas'"



_____
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
You've got a program with a parser calling another program with a parser and the quotes are getting dropped somewhere.

But the error is coming from the first program with the parser (the command-interpreter) - none of them are coming from the called programs. I would think that it would be fine, though, since this same command-interpreter is working when I simply call the program without the CMD /C part.

Again the problem is that I would have to use CMD /C because I don't know if the parm for what to run is going to be an actual program, interpreter command (like "del" in the example), or batch file.

Two " returns this:

Code:
The filename, directory name, or volume label syntax is incorrect.

The "' combination returns the same error as before ("C:\Program is not bla bla").

----------
Measurement is not management.
 
Have you tried your batch file, or command line, on another machine to see if it generates a different or similar error?

Has that command line ever worked in the past for you?

Do your Environmental Variables appear correct?

Have you tried a different Keyboard?

Try Safe Mode with a Command Prompt (Do you have this problem in Safe Mode?).

Try running ChkDsk to check your drive for errors. Right-click your Drive icon/ Properties/ Tools/ Error Checking. Select both boxes.

Run the System File Checker program from the Run Box by typing.....Sfc /Scannow in it and have your XP CD handy.
 
What I meant is that you're starting with a command shell which has to parse what you typed to figure out to run another instance of cmd.exe and pass the rest of what typed as parameters to that. The second (called) instance is what is throwing the error.

What appears to be happening is that cmd.exe wants only 1 string as a parameter (except for something to do with '&&'.) Maybe this will suggest something to somebody else:
Code:
H:\>cmd /?
Starts a new instance of the Windows XP command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)
/Q      Turns echo off
/D      Disable execution of AutoRun commands from registry (see below)
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be
        Unicode
/T:fg   Sets the foreground/background colors (see COLOR /? for more info)
/E:ON   Enable command extensions (see below)
/E:OFF  Disable command extensions (see below)
/F:ON   Enable file and directory name completion characters (see below)
/F:OFF  Disable file and directory name completion characters (see below)
/V:ON   Enable delayed environment variable expansion using ! as the
        delimiter. For example, /V:ON would allow !var! to expand the
        variable var at execution time.  The var syntax expands variables
        at input time, which is quite a different thing when inside of a FOR
        loop.
/V:OFF  Disable delayed environment expansion.

Note that multiple commands separated by the command separator '&&'
are accepted for string if surrounded by quotes.  Also, for compatibility
reasons, /X is the same as /E:ON, /Y is the same as /E:OFF and /R is the
same as /C.  Any other switches are ignored.

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

    1.  If all of the following conditions are met, then quote characters
        on the command line are preserved:

        - no /S switch
        - exactly two quote characters
        - no special characters between the two quote characters,
          where special is one of: &<>()@^|
        - there are one or more whitespace characters between the
          the two quote characters
        - the string between the two quote characters is the name
          of an executable file.

    2.  Otherwise, old behavior is to see if the first character is
        a quote character and if so, strip the leading character and
        remove the last quote character on the command line, preserving
        any text after the last quote character.

_____
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top