long filename -> short filename conversion incorrect

Discussion in 'Windows XP General' started by Han, Dec 11, 2008.

  1. Han

    Han Guest

    I've been using the %~sI method of converting a batch file argument from a
    long file name (with potential spaces) into a short file name. This has
    worked well for ages but I've not run into a problem where a specific
    directory path won't convert properly. E.g. If I have the following path:

    d:\app\administrator\product\11.1.0\client_1\

    Running the following produces the wrong result:

    set O=%~s1

    Produces d:\app\ADMINI~1\product\111~1.0\client_1nt_1

    Notice the extra nt_1? Does anyone know where that comes from and how to
    avoid it?
     
    Han, Dec 11, 2008
    #1
    1. Advertisements

  2. "Han" <> wrote in message
    news:...
    > I've been using the %~sI method of converting a batch file argument from a
    > long file name (with potential spaces) into a short file name. This has
    > worked well for ages but I've not run into a problem where a specific
    > directory path won't convert properly. E.g. If I have the following
    > path:
    >
    > d:\app\administrator\product\11.1.0\client_1\
    >
    > Running the following produces the wrong result:
    >
    > set O=%~s1
    >
    > Produces d:\app\ADMINI~1\product\111~1.0\client_1nt_1
    >
    > Notice the extra nt_1? Does anyone know where that comes from and how to
    > avoid it?


    I think there is a little more to your code than
    set O=%~s1
    Best to post the whole relevant section.
     
    Pegasus \(MVP\), Dec 11, 2008
    #2
    1. Advertisements

  3. Han

    Han Guest

    "Pegasus (MVP)" wrote:

    >
    > I think there is a little more to your code than
    > set O=%~s1
    > Best to post the whole relevant section.
    >


    I tried to narrow down the problem to a very simple test case. The entire
    batch file in this case is:

    shortname.bat:

    @set O=%~s1
    @echo %O%

    If I run
    shortname "c:\Program Files\Windows Media Player\Sample Playlists"

    I get
    c:\PROGRA~1\WINDOW~2\SAMPLE~1

    which looks correct.

    If I run
    shortname "d:\app\administrator\product\11.1.0\client_1"

    I get
    d:\app\ADMINI~1\product\111~1.0\client_1nt_1

    which isn't correct.
     
    Han, Dec 11, 2008
    #3
  4. "Han" <> wrote in message
    news:...
    >
    >
    > "Pegasus (MVP)" wrote:
    >
    >>
    >> I think there is a little more to your code than
    >> set O=%~s1
    >> Best to post the whole relevant section.
    >>

    >
    > I tried to narrow down the problem to a very simple test case. The entire
    > batch file in this case is:
    >
    > shortname.bat:
    >
    > @set O=%~s1
    > @echo %O%
    >


    The code
    set O=%~s1
    requires a "for" statement. I cannot see a "for" statement in your code. If
    you don't have one then I suggest you describe what you're trying to
    achieve.
     
    Pegasus \(MVP\), Dec 11, 2008
    #4
  5. Han

    Han Guest

    "Pegasus (MVP)" wrote:

    >
    > The code
    > set O=%~s1
    > requires a "for" statement. I cannot see a "for" statement in your code. If
    > you don't have one then I suggest you describe what you're trying to
    > achieve.
    >
    >
    >


    I'm kind of surprised at that because I've been using that syntax without
    for loops for ages. I never got the impression that they were exclusively
    for for loops.

    Anyways, what I'm trying to do is convert a given path to its shortname
    equivalent. The reason for this is to eliminate the potential for spaces in
    paths that have downstream impact on things that can't handle the spaces.
    The %~s1 substitution is supposed to replace the first parameter to the batch
    file with its shortname equivalent.
     
    Han, Dec 12, 2008
    #5
  6. "Han" <> wrote in message
    news:...
    >
    >
    > "Pegasus (MVP)" wrote:
    >
    >>
    >> The code
    >> set O=%~s1
    >> requires a "for" statement. I cannot see a "for" statement in your code.
    >> If
    >> you don't have one then I suggest you describe what you're trying to
    >> achieve.
    >>
    >>
    >>

    >
    > I'm kind of surprised at that because I've been using that syntax without
    > for loops for ages. I never got the impression that they were exclusively
    > for for loops.
    >
    > Anyways, what I'm trying to do is convert a given path to its shortname
    > equivalent. The reason for this is to eliminate the potential for spaces
    > in
    > paths that have downstream impact on things that can't handle the spaces.
    > The %~s1 substitution is supposed to replace the first parameter to the
    > batch
    > file with its shortname equivalent.


    It is now becoming clear that you are invoking your batch file like so:
    han.bat "%cd%"
    It would have been helpful if you had stated this important fact right at
    the start to avoid the confusion.

    In this particular case you do not need a "for" statement.

    I suspect that you found a bug. The following batch file, when invoked with
    a parameter as above, illustrates it. It also shows a work-around that
    avoids the issue.

    If you want to get the opinion of some top-notch batch file experts then I
    suggest you repost your question here: alt.msdos.batch.nt, preferably giving
    full details about your batch file and how you invoke it.

    @echo off
    echo The short path is %~s1

    pushd "%cd%"
    echo Q > "%temp%\debug.scr"
    debug < "%temp%\debug.scr" > nul
    echo The short path is %cd%
    popd
     
    Pegasus \(MVP\), Dec 12, 2008
    #6
  7. "Han" <> wrote in message
    news:...
    >
    >
    > "Pegasus (MVP)" wrote:
    >
    >>
    >> The code
    >> set O=%~s1
    >> requires a "for" statement. I cannot see a "for" statement in your code.
    >> If
    >> you don't have one then I suggest you describe what you're trying to
    >> achieve.
    >>
    >>
    >>

    >
    > I'm kind of surprised at that because I've been using that syntax without
    > for loops for ages. I never got the impression that they were exclusively
    > for for loops.
    >
    > Anyways, what I'm trying to do is convert a given path to its shortname
    > equivalent. The reason for this is to eliminate the potential for spaces
    > in
    > paths that have downstream impact on things that can't handle the spaces.
    > The %~s1 substitution is supposed to replace the first parameter to the
    > batch
    > file with its shortname equivalent.


    Here is a variant of the previous batch file. It relies on getting the path
    as a parameter, same as your batch file.
    @echo off
    pushd "%1"
    echo Q > "%temp%\debug.scr"
    debug < "%temp%\debug.scr" > nul
    echo The short path is %cd%
    popd
     
    Pegasus \(MVP\), Dec 12, 2008
    #7
  8. Han

    Han Guest

    "Pegasus (MVP)" wrote:

    >
    > "Han" <> wrote in message
    > news:...
    > >
    > >
    > > "Pegasus (MVP)" wrote:
    > >
    > >>
    > >> The code
    > >> set O=%~s1
    > >> requires a "for" statement. I cannot see a "for" statement in your code.
    > >> If
    > >> you don't have one then I suggest you describe what you're trying to
    > >> achieve.
    > >>
    > >>
    > >>

    > >
    > > I'm kind of surprised at that because I've been using that syntax without
    > > for loops for ages. I never got the impression that they were exclusively
    > > for for loops.
    > >
    > > Anyways, what I'm trying to do is convert a given path to its shortname
    > > equivalent. The reason for this is to eliminate the potential for spaces
    > > in
    > > paths that have downstream impact on things that can't handle the spaces.
    > > The %~s1 substitution is supposed to replace the first parameter to the
    > > batch
    > > file with its shortname equivalent.

    >
    > Here is a variant of the previous batch file. It relies on getting the path
    > as a parameter, same as your batch file.
    > @echo off
    > pushd "%1"
    > echo Q > "%temp%\debug.scr"
    > debug < "%temp%\debug.scr" > nul
    > echo The short path is %cd%
    > popd
    >
    >


    Thanks for the suggestion I'll give it a shot.
     
    Han, Dec 15, 2008
    #8
  9. Han

    send2castle

    Joined:
    Sep 25, 2012
    Messages:
    1
    Likes Received:
    0
    Because of the "." in the Folder names., The buffer.Reads it as another extend of buffer.
    So the foldername at last of remainins spaces repeats.

    13 chars
    use mid String to extract last 13 char from main string and save the main string. In ur case 11.1.0
    Then it will be Okay
     
    send2castle, Sep 25, 2012
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick

    Long Story Short XP Help

    Nick, Aug 22, 2003, in forum: Windows XP General
    Replies:
    0
    Views:
    298
  2. Replies:
    16
    Views:
    915
    David Candy
    Nov 30, 2004
  3. Guest

    long and short filename copy

    Guest, Aug 21, 2005, in forum: Windows XP General
    Replies:
    1
    Views:
    240
    Don Taylor
    Aug 21, 2005
  4. Gary Roach

    problem setting short filename

    Gary Roach, Oct 27, 2005, in forum: Windows XP General
    Replies:
    3
    Views:
    364
    David Candy
    Oct 27, 2005
  5. PiErre
    Replies:
    4
    Views:
    943
    Wesley Vogel
    Jan 17, 2007
Loading...

Share This Page