Portable filename comparison

K

Ken Dyck

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
'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
 
P

Peter Hansen

Ken said:
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

'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:
.... from win32api import GetLongPathName
.... return GetLongPathName(shortname)
....'c:\\Program Files'

-Peter
 

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

Forum statistics

Threads
474,175
Messages
2,570,944
Members
47,492
Latest member
gabbywilliam

Latest Threads

Top