How to test if two strings point to the same file or directory?

Tim Chase python.list at tim.thechases.com
Sun Dec 17 08:13:17 EST 2006


> The current setup will not "silently fail when run on win32". How could
> it? It doesn't exist; it can't be run.

Ah...didn't know which it did (or didn't do) as I don't have a 
win32 box at hand on which to test it.

In chasing the matter further, the OP mentioned that their 
particular problem was related to tilde-expansion/compression 
which python doesn't seem to distinguish.

To take this into consideration, there's some advice at

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee559c99d54d970b/b71cb7ac1b7be105

where Chris Tismer has an example function/module that uses Win32 
API calls to normalize a path/filename to the short-name equiv. 
It looks like this could be integrated into the previous code I 
posted, so you'd have something like

os.path.samefile = lambda f1, f2: (
	LongToShort(abspath(f1)).lower() ==
	LongToShort(abspath(f2)).lower()
	)

As stated, it's a bit fly-by-the-seat-of-the-pants as I don't 
have any boxes running Win32 here at home, but that would be the 
general gist of the idea.

It would be handy to add it, as the semantic meaning is the same 
across platforms, even if the implementation details are vastly 
different.  One of the reasons I use python is because it usually 
crosses platform boundaries with nary a blink.

Just a few more ideas,

-tkc





More information about the Python-list mailing list