473,604 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python utility convert Windows long file name into 8.3 DOS format

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
Jul 18 '05 #1
7 11066
On Thu, 28 Oct 2004 06:47:28 GMT, Ben Kial <be*****@hotmai l.com> wrote:
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"?

import win32api
win32api.GetSho rtPathName('D:/share/from_roadwarrio r/simon/python/RandomizeScreen Saver/RandomizeScreen Saver.pyw')

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

--
Cheers,
Simon B,
si************@ gmail.com,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #2
Simon Brunning wrote:
On Thu, 28 Oct 2004 06:47:28 GMT, Ben Kial <be*****@hotmai l.com> wrote:
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"?


import win32api
win32api.Ge tShortPathName( 'D:/share/from_roadwarrio r/simon/python/RandomizeScreen Saver/RandomizeScreen Saver.pyw')


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


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

--
Vincent Wehren
Jul 18 '05 #3
On Thu, 28 Oct 2004 10:55:16 +0200, vincent wehren
<vi*****@visual trans.de> wrote:
Just note that GetShortPathNam e 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.

--
Cheers,
Simon B,
si************@ gmail.com,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #4
Simon Brunning wrote:
On Thu, 28 Oct 2004 10:55:16 +0200, vincent wehren
<vi*****@visual trans.de> wrote:
Just note that GetShortPathNam e 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.


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.
--
Vincent Wehren

Jul 18 '05 #5
vincent wehren wrote:
Simon Brunning wrote:
On Thu, 28 Oct 2004 10:55:16 +0200, vincent wehren
<vi*****@visual trans.de> wrote:
Just note that GetShortPathNam e 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.


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
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #6

"Simon Brunning" <si************ @gmail.com> wrote in message
news:ma******** *************** *************** @python.org...
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...
Jul 18 '05 #7
Steve Holden wrote:
vincent wehren wrote:
Simon Brunning wrote:
On Thu, 28 Oct 2004 10:55:16 +0200, vincent wehren
<vi*****@visual trans.de> wrote:

Just note that GetShortPathNam e 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.

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 :-)


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 authoritativene ss on the
subject of Windows file names - long or short - either - I just blindly
trust MSDN! ;)

Regards,

--
Vincent Wehren

regards
Steve

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
35519
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate),
10
2021
by: Paul Kooistra | last post by:
I need a tool to browse text files with a size of 10-20 Mb. These files have a fixed record length of 800 bytes (CR/LF), and containt records used to create printed pages by an external company. Each line (record) contains an 2-character identifier, like 'A0' or 'C1'. The identifier identifies the record format for the line, thereby allowing different record formats to be used in a textfile. For example: An A0 record may consist of:
2
4438
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
0
4549
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 349 open ( +7) / 3737 closed (+25) / 4086 total (+32) Bugs : 939 open (-12) / 6648 closed (+60) / 7587 total (+48) RFE : 249 open ( -8) / 278 closed (+12) / 527 total ( +4) New / Reopened Patches ______________________
0
1228
by: Lie | last post by:
Yesterday I installed compiz-icon in my Ubuntu. Today, when I go to the python interpreter, I happen to do this: ### START OF PYTHON SESSION ### Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30) on linux2 Type "help", "copyright", "credits" or "license" for more information. Welcome to Python 2.5! This is the online help utility.
0
8419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8406
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8274
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3954
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2433
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.