Python utility convert Windows long file name into 8.3 DOS format

B

Ben Kial

Is there a Python program to convert Windows long filename, like "c:\Program
Files" into the old DOS 8.3 format, like "c:\Progra~1"?

Thanks in advance,

Ben
 
S

Simon Brunning

Is there a Python program to convert Windows long filename, like "c:\Program
Files" into the old DOS 8.3 format, like "c:\Progra~1"?
'D:/share/FROM_R~1/simon/python/RANDOM~1/RANDOM~1.PYW'
 
V

vincent wehren

Simon said:
'D:/share/FROM_R~1/simon/python/RANDOM~1/RANDOM~1.PYW'

Just note that GetShortPathName expects a valid and accessible path in
your file system.
 
S

Simon Brunning

Just note that GetShortPathName expects a valid and accessible path in
your file system.

Which is just as it should be. Files that don't exist don't *have*
short names. One might be able to put together a function that
*guesses* what short name Windows would be likely to give a new file
with a given long name, but it would be pretty unreliable, I reckon.
 
V

vincent wehren

Simon said:
Which is just as it should be. Files that don't exist don't *have*
short names. One might be able to put together a function that
*guesses* what short name Windows would be likely to give a new file
with a given long name, but it would be pretty unreliable, I reckon.

Exactly. And on top of that, there may be situations where files that
*do* exist *don't* have a 8.3 alias, making any such guesswork even
harder. So in retrospect, the correct answer to OP's question should be:
"No. There is no conversion utility", as the relationship between long
name - short name is not on of a-to-b conversion.
 
S

Steve Holden

vincent said:
Exactly. And on top of that, there may be situations where files that
*do* exist *don't* have a 8.3 alias, making any such guesswork even
harder. So in retrospect, the correct answer to OP's question should be:
"No. There is no conversion utility", as the relationship between long
name - short name is not on of a-to-b conversion.
well that's new information to me, so thanks - I just assumed that any
long filename could be munged. But I think that it's just useful
additional information rather than the "correct answer", since by itself
it would have been rather less than helpful to the OP :)

regards
Steve
 
R

Richard Brodie

One might be able to put together a function that
*guesses* what short name Windows would be likely to give a new file
with a given long name, but it would be pretty unreliable, I reckon.

And possibly patent infringing...
 
V

vincent wehren

Steve said:
well that's new information to me, so thanks - I just assumed that any
long filename could be munged. But I think that it's just useful
additional information rather than the "correct answer", since by itself
it would have been rather less than helpful to the OP :)

I guess sleep deprivation has given rise to a little wickedness in my
writing. I forget to "wink" ;) ;)

Apart from that, you won't hear me claim any authoritativeness on the
subject of Windows file names - long or short - either - I just blindly
trust MSDN! ;)

Regards,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top