blanks in environment variable paths

Jul 25, 2010
2
0
#1
Hi,

Appreciate if anyone can suggest how to overcome the presence of blanks in an environment variable used as a path in 4NT or TCC. The issue has arisen due to my root diretcory being moved onto a path that has imbedded blanks.

For example:
set apath=c:\directory with blanks\sub

will not be parsed correctly in:
dir %apath

although this will work
dir "%apath

I use these paths extensively in various BAT files and in normal command line mode and do not want to have to make these changes if there is another easy solution.

Thanks.
 
Dec 17, 2009
29
0
Germany
#2
Using the variable definition from your example, Echo %apath gives:
C:\4NT\echo %apath
c:\directory with blanks\sub
The problem may be caused by the dir command, which does not accept paths with blanks, whether or not they are stored inside environment variables. The help file states:
When you use DIR on an LFN drive, you must quote any file names which contain white space or special characters

C:\dir c:\directory with blanks

Volume in drive C is 40GB Serial number is 8495:9f09
TCC: (Sys) Das System kann die angegebene Datei nicht finden.
"C:\directory"
0 bytes in 0 files and 0 dirs
33.082.953.728 bytes free

Volume in drive C is 40GB Serial number is 8495:9f09
TCC: (Sys) Das System kann die angegebene Datei nicht finden.
"C:\with"
0 bytes in 0 files and 0 dirs
33.082.953.728 bytes free

Volume in drive C is 40GB Serial number is 8495:9f09
TCC: (Sys) Das System kann die angegebene Datei nicht finden.
"C:\blanks"
0 bytes in 0 files and 0 dirs
33.082.953.728 bytes free
C:\dir "c:\directory with blanks" shows the directory normally.

A possible solution could be defining your own dir-like command using pdir, because it offers an automatic quoting of file names with blanks for the display option:

The /(...) option specifies which fields you want to display and how to format them. (You can have multiple /(...) options on a line.) The syntax is:

f[...] File or Directory name (case sensitive)

P SFN path
p LFN path
N SFN filename
n LFN filename (default)

q Enclose the filename in double quotes if it contains whitespace or special characters (not available in TCC/LE)
 
#3
| Using the variable definition from your example, *Echo* %apath gives:
|
| ---Quote---
|| C:\4NT\echo %apath
|| c:\directory with blanks\sub
| ---End Quote---
| The problem may be caused by the *dir* command, which does not
| accept paths with blanks, whether or not they are stored inside
| environment variables. The help file states: When you use DIR on an
| LFN drive, you must quote any file names which contain white space
| or special characters

The problem is not the caused by the command, but by the file naming
convention introduced with LFNs which is incompatible with all previous
command syntax, and requires enclosing some filenames in quotation marks.

| A possible solution could be defining your own dir-like command
| using *pdir*, because it offers an automatic quoting of file names
| with blanks for the display option:
...

That option controls the output of PDIR, not its input. The @QUOTE
function can be used to quote file names only when needed, e.g., using your
above defined variable APATH:

dir %@quote[%apath]

@QUOTE detects if the path is already quoted and will not quote it doubly.
--
HTH, Steve
 
Jul 25, 2010
2
0
#4
Thanks for your suggestions - seems like there is no easy fix other than avoiding blanks in LFN - which is what I do anyway when it is under my control.

The @QUOTE does seem useful however and I'll see where I might be able to make use of that.

BH/seng
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,586
46
Albuquerque, NM
prospero.unm.edu
#5
Thanks for your suggestions - seems like there is no easy fix other than avoiding blanks in LFN - which is what I do anyway when it is under my control.
When it's not under your control, SUBST is your friend. Or directory aliases.

Code:
subst q: "c:\documents and settings"
alias progs:=%programfiles\
 [/quote]