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

Problems with %-sign in filenames/directory names

Discussion in 'Support' started by BigMike, Mar 27, 2009.

  1. BigMike

    Joined:
    Mar 26, 2009
    Messages:
    3
    Likes Received:
    0
    Hi,

    I got aware of 4nt when reading a page about tips & tricks using the windows command line. After the problem occured with the trial version linked on this page, I came here for an update and found, that 4nt was replaced by tcc (and that there's a free version - thank you :) ).

    It seems there's a problem with handling directories and files, if the name contains a %-sign.

    Windows standard command interpretor handles these names without problems, but 4nt/tcc doesn't. I can't access directories or files containing a %-sign. Your interpretor tells me, that there's no such file/directory.

    Just create a file containing a %-sign via explorer and try to delete it with your command interpretor or create a directory in explorer and try to switch to it via "cd dirname_containing_%" to reproduce the problem.

    I tried this with
    4nt 8,02.106 trial
    tcc le 10,00,63 (on your page it's reported as build 62??)
    on Win XP, SP3 32bit.

    Thanks so far,
    BigMike
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,066
    Likes Received:
    30
    On Fri, 27 Mar 2009 06:52:50 -0500, BigMike <> wrote:

    |Hi,
    |
    |I got aware of 4nt when reading a page about tips & tricks using the windows command line. After the problem occured with the trial version linked on this page, I came here for an update and found, that 4nt was replaced by tcc (and that there's a free version - thank you :) ).
    |
    |It seems there's a problem with handling directories and files, if the name contains a %-sign.

    v:\> touch /c t%%.txt
    2009-03-27 08:07:28.169 V:\t%.txt

    v:\> dir /k /m t*
    2009-03-27 08:07 0 t%.txt
    2009-03-16 23:47 1,232 test.txt

    v:\> del t%%.txt
    Deleting V:\t%.txt
    1 file deleted
    --
    - Vince
     
  3. BigMike

    Joined:
    Mar 26, 2009
    Messages:
    3
    Likes Received:
    0
    Thank you :)

    Ok, in this case the behaviour is just different. With CMD a single % is enough. In TCC you have to double the %
     
  4. Jay Sage

    Joined:
    Jun 2, 2008
    Messages:
    284
    Likes Received:
    1
    Vince didn't explain this, but it arises from TCC's acceptance of
    environment variables with a single percent sign rather than percent
    signs before AND AFTER the variable name.

    Another approach (useful in many cases where special features might
    cause a problem) is to use the SETDOS command with the /X option to turn
    off the feature. The command "setdos /x-3" will turn off the processing
    of environment variables, making the percent character just another
    regular character. When the operations are complete, "setdos /x+3" or
    "setdos /x0" will restore normal operation.

    -- Jay
     
  5. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    604
    Likes Received:
    0
    Re: Problems with %-sign in filenames/directory names

    An overkill that would work if you only use commands at the command
    line, but did not use batch files, would be

    SETDOS /X-3

    Then the % character is no longer special. This has drastic
    implications for all batch files, however.

    On Fri, Mar 27, 2009 at 6:04 AM, BigMike <> wrote:



    --
    Jim Cook
    2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
    Next year they're Sunday.
     
  6. BigMike

    Joined:
    Mar 26, 2009
    Messages:
    3
    Likes Received:
    0
    Many thanks again, I'll get used to this behaviour and with the explanation, why the behaviour is as it is all questions are more than answered :)
     
  7. dim

    dim Dimitry Andric

    Joined:
    May 31, 2008
    Messages:
    203
    Likes Received:
    0
    On 2009-03-27 14:04, BigMike wrote:

    The problem occurs because of the way environment variables are parsed,
    which is done differently in CMD and TCC. Let's suppose you set a
    variable 'foo':

    set foo=bar

    and you create a directory using this syntax:

    mkdir foo%foo

    then the results will be different for CMD and TCC: CMD will create a
    directory named 'foo%foo', while TCC creates 'foobar'. This is because
    TCC interprets '%foo' as a request to expand the variable 'foo', while
    CMD doesn't. It needs an extra % sign at the end, as in '%foo%', to do
    the expansion.

    E.g. TCC must always have double % signs to escape variable expansion,
    while CMD doesn't need to.
     

Share This Page