If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
long filename - short filename conversion incorrect
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? |
Ads |
#2
|
|||
|
|||
long filename - short filename conversion incorrect
"Han" wrote in message ... 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. |
#3
|
|||
|
|||
long filename - short filename conversion incorrect
"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. |
#4
|
|||
|
|||
long filename - short filename conversion incorrect
"Han" wrote in message ... "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. |
#5
|
|||
|
|||
long filename - short filename conversion incorrect
"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. |
#6
|
|||
|
|||
long filename - short filename conversion incorrect
"Han" wrote in message ... "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 he 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 |
#7
|
|||
|
|||
long filename - short filename conversion incorrect
"Han" wrote in message ... "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 |
#8
|
|||
|
|||
long filename - short filename conversion incorrect
"Pegasus (MVP)" wrote: "Han" wrote in message ... "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. |
Thread Tools | |
Display Modes | |
|
|