1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

blanks in environment variable paths

Discussion in 'Support' started by seng, Jul 27, 2010.

  1. seng

    Joined:
    Jul 25, 2010
    Messages:
    2
    Likes Received:
    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.
     
  2. Arminius

    Joined:
    Dec 17, 2009
    Messages:
    15
    Likes Received:
    0
    Using the variable definition from your example, Echo %apath gives:
    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

    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:

     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    | 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
     
  4. seng

    Joined:
    Jul 25, 2010
    Messages:
    2
    Likes Received:
    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
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    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]
     

Share This Page