A simple replacement of the os.path.samefile() function not existing on the Windows platform. MAC/Unix supported in standard way :).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | def samefile(f1, f2):
'''
A simple replacement of the os.path.samefile() function not existing
on the Windows platform.
MAC/Unix supported in standard way :).
Author: Denis Barmenkov <denis.barmenkov@gmail.com>
Source: code.activestate.com/recipes/576886/
Copyright: this code is free, but if you want to use it, please
keep this multiline comment along with function source.
Thank you.
2009-08-19 20:13
'''
try:
return os.path.samefile(f1, f2)
except AttributeError:
f1 = os.path.abspath(f1).lower()
f2 = os.path.abspath(f2).lower()
return f1 == f2
|
It simply doesn't work, except on the most simple cases.
What about SUBSTed drives? Junction points? Symbolic links? Network shares? Neither of them are resolved by a simple abspath call.
Sorry but a "true" samefile replacement will take much more than that.
Its not a 'all ways solution' but a simple example for testing two files on local drive.
Windows extra entities are too complicated to work with ;)
Recipe renamed.
Found another win32 algorithm:
http://timgolden.me.uk/python/win32_how_do_i/see_if_two_files_are_the_same_file.html