473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Portable filename comparison

Is there a way with Python 2.2 to portably test the equivalence of two
filenames?

The os.path.samefile function seems to do what I want, but it is only
available on Unix and Mac. I need something that works on Windows.

The os.path.normcase and os.path.normpath functions are available on all
platforms, but don't quite get me there. For example, on Windows
os.path.normcase(os.path.normpath("C:\Program Files")) 'c:\\program files' os.path.normcase(os.path.normpath("C:\PROGRA~1"))

'c:\\progra~1'

I suppose I could find a way to call into the Win32 API directly, but I'd
prefer to use a portable solution if I can find one.

Any suggestions?

Ken
Jul 18 '05 #1
1 1685
Ken Dyck wrote:

Is there a way with Python 2.2 to portably test the equivalence of two
filenames?

The os.path.samefile function seems to do what I want, but it is only
available on Unix and Mac. I need something that works on Windows.

The os.path.normcase and os.path.normpath functions are available on all
platforms, but don't quite get me there. For example, on Windows
os.path.normcase(os.path.normpath("C:\Program Files")) 'c:\\program files' os.path.normcase(os.path.normpath("C:\PROGRA~1")) 'c:\\progra~1'

I suppose I could find a way to call into the Win32 API directly, but I'd
prefer to use a portable solution if I can find one.


I believe you need to make your own, since the whole concept of thus
mungled long names on Windows is definitely not portable.

Here's a snippet that might make this seem much easier:
def expand(shortname): .... from win32api import GetLongPathName
.... return GetLongPathName(shortname)
.... expand('c:\\progra~1')

'c:\\Program Files'

-Peter
Jul 18 '05 #2

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

Similar topics

5
by: Danilo Kempf | last post by:
Folks, maybe one of you could be of help with this question: I've got a relatively portable application which I'm extending with a plugin interface. While portability (from a C perspective) is...
10
by: Jason Curl | last post by:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers to...
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
2
by: Brian Parker | last post by:
I have an ArrayList ( strings ) of filenames like such: fred.out inctructions.txt luncheon01.jpg luncheon02.jpg luncheon05.jpg luncheon11.jpg HeebieJeebie.cs ...etc..
2
by: octangle | last post by:
Create enumerated values using the three highest bits as bit flags that define comparison operators. VERSION A: ---------- enum eCriteria { eCriteriaOne = 1, eCriteriaTwo = 2,
1
by: Fabrizio | last post by:
My web cam save a file each minute with a name like this "history20070611s202635195.jpg" Do you know a script in php that can animate the last 60 jpg ? What I like is something like this: ...
16
by: Noob | last post by:
Hello, I've rewritten a function (greater_or_equal) that relies on implementation-defined behavior and availability of exact-width integers, with the goal of making the new implementation...
1
by: James Hahn | last post by:
I have a ListView that displays files selected from various folders using a user-specified selection rule. I want to sort the files in various ways and have implemented a sorter class to do it,...
16
by: Stef Mientki | last post by:
hello, How can I find the correct case of a filename ? Background in my program I use case sensitive filenames, just like Python requires. Now I've integrated pdb into the program, but pdb...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.