blanks in environment variable paths

Jul 25, 2010
5
0
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
39
0
Germany
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)
 
May 20, 2008
3,515
4
Elkridge, MD, USA
| 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
5
0
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
4,466
88
Albuquerque, NM
prospero.unm.edu
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]
 
Similar threads
Thread starter Title Forum Replies Date
fpefpe How to? Comparing strings with blanks Support 5
BobK How to? Handling filenames with blanks at command line Support 3
M Padding with blanks... Support 4
M Concatenating blanks to strings???? Support 2
Peter Murschall v27.00.16/17: ENDLOCAL with exporting variables wipes out the complete Environment Support 2
T Is there a way to maintain the position in the environment list, while debugging? Support 10
D Unnecessary environment dependencies of TCC.EXE Support 3
T Portable Take Command installation for VDI environment Support 2
D v23 environment oddity Support 3
gschizas Take Command (Environment) doesn't show v2 ANSI colors Support 30
M Save the environment .. ;-) Support 2
Charles Dye Read-only environment variables wiped by SETLOCAL / ENDLOCAL Support 5
J Shell nesting level, and inherited environment variables Support 10
J Set environment variable from stdout of command Support 3
nickles Passing a variable to a command w/o adding it to the local environment Support 7
vefatica Environment refresh? Support 0
rfaquino WAD Apparently a bug when expanding environment variable %ProgramFiles(x86) Support 2
B WAD environment variable in TCC.exe Support 2
SeoulBigChris Save Environment (Tabs) on Exit? Support 3
fpefpe Documentation environment variables Support 3
fpefpe How to? Environment Variables changed Support 2
vefatica OT: Rex, how does CMD handle its environment? Support 0
M Updating environment variable from C++ fails erratically in version 14... Support 57
Frank problem with environment variable x86 vs. x64 Support 2
fpefpe volatile environment Support 5
daniel347x How to get Take Command to read in all current system environment variables that CMD.EXE sees? Support 13
D Environment in elevated process Support 1
Peter Bratton IDE environment window display Support 0
D Environment variable oddity Support 12
vefatica Got IDE's environment tab back Support 0
vefatica What environment variables does IDE need? Support 3
tinjaw Looking for best practice for custom environment on tabs Support 0
E Environment variable in tcmd.ini Support 14
I Environment variable in OPTION screen? Support 2
E Environment variables, set and input Support 2
J trouble redirecting output to environment variable Support 7
D Parsing an array variable to an array does not work Support 5
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
P Inserting string into a variable. Support 3
vefatica Setting array variable ignores leading spaces (and @execarray doesn't) Support 4
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R Difference between TCC and CMD: variable names with hyphens Support 4
Joe Caverly Get a variable type Support 2
M How to set Path variable for non-executable file extensions in 4DOS Support 8
rps For loop internal %_for_files variable? Support 2
A How to safely print variable's value without quotes? Support 9
vefatica Array name in a variable? Support 3
nikbackm TCC 20 variable expansion bug Support 6
X How to set %_INIREAD result to variable Support 5
Charles Dye _USBS variable Support 2

Similar threads