PC Review


Reply
Thread Tools Rate Thread

long filename -> short filename conversion incorrect

 
 
Han
Guest
Posts: n/a
 
      11th Dec 2008
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?
 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      11th Dec 2008

"Han" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
 
Han
Guest
Posts: n/a
 
      11th Dec 2008


"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.

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      12th Dec 2008

"Han" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> "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.


 
Reply With Quote
 
Han
Guest
Posts: n/a
 
      12th Dec 2008


"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.
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      12th Dec 2008

"Han" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> "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


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      12th Dec 2008

"Han" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> "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


 
Reply With Quote
 
Han
Guest
Posts: n/a
 
      15th Dec 2008


"Pegasus (MVP)" wrote:

>
> "Han" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> >
> > "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.
 
Reply With Quote
 
New Member
Join Date: Sep 2012
Posts: 1
 
      25th Sep 2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HttpPostedFile.saveas(filename) issue when the filename is used "-" as a part of the filename. Ken Microsoft Dot NET Framework 0 25th Feb 2009 11:58 PM
Fix for long, long, long deleting and copying of files? Hope Windows Vista General Discussion 14 11th Feb 2008 01:12 AM
long and short filename copy =?Utf-8?B?U2luY2xhaXI=?= Windows XP General 1 21st Aug 2005 07:02 PM
Long filename conversion Jens Mose Pedersen Microsoft Windows 2000 CMD Promt 1 9th Dec 2003 01:56 PM
ASUS A7V133 Boot Fail (long, short, short beep code) Brent L. Harritt Asus Motherboards 5 26th Nov 2003 09:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:27 PM.