A Windows XP help forum. PCbanter

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.

Go Back   Home » PCbanter forum » Microsoft Windows XP » General XP issues or comments
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

long filename - short filename conversion incorrect



 
 
Thread Tools Display Modes
  #1  
Old December 11th 08, 09:27 PM posted to microsoft.public.windowsxp.general
Han
external usenet poster
 
Posts: 4
Default 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  
Old December 11th 08, 09:57 PM posted to microsoft.public.windowsxp.general
Pegasus \(MVP\)[_2702_]
external usenet poster
 
Posts: 1
Default 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  
Old December 11th 08, 10:41 PM posted to microsoft.public.windowsxp.general
Han
external usenet poster
 
Posts: 4
Default 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  
Old December 11th 08, 11:03 PM posted to microsoft.public.windowsxp.general
Pegasus \(MVP\)[_2704_]
external usenet poster
 
Posts: 1
Default 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  
Old December 12th 08, 04:45 PM posted to microsoft.public.windowsxp.general
Han
external usenet poster
 
Posts: 4
Default 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  
Old December 12th 08, 05:19 PM posted to microsoft.public.windowsxp.general
Pegasus \(MVP\)[_2710_]
external usenet poster
 
Posts: 1
Default 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  
Old December 12th 08, 07:04 PM posted to microsoft.public.windowsxp.general
Pegasus \(MVP\)[_2711_]
external usenet poster
 
Posts: 1
Default 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  
Old December 15th 08, 04:39 PM posted to microsoft.public.windowsxp.general
Han
external usenet poster
 
Posts: 4
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off






All times are GMT +1. The time now is 11:32 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.