I have a python script that is giving me a hard time on Ubuntu 12.02 with Python 2.7.3.
PS: it runs without problems on Windows.
>>> import os
>>> import shutil
>>> shutil.copy("/mnt/my_network_dive/somewhere/sample.xml", "/mnt/my_network_drive/COMPLETED/")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/shutil.py", line 117, in copy
copyfile(src, dst)
File "/usr/lib/python2.7/shutil.py", line 69, in copyfile
raise Error("`%s` and `%s` are the same file" % (src, dst))
shutil.Error: `/mnt/my_network_dive/somewhere/sample.xml` and `/mnt/my_network_drive/COMPLETED/sample.xml` are the same file
Checking some properties of the files:
>>> os.path.exists("/mnt/my_network_drive/somewhere/sample.xml")
True
>>> os.path.exists("/mnt/my_network_drive/COMPLETED/sample.xml")
True
>>> os.stat("/mnt/my_network_drive/somewhere/sample.xml")
posix.stat_result(st_mode=33272, st_ino=4913809333, st_dev=25L, st_nlink=1, st_uid=1000, st_gid=0, st_size=5447, st_atime=1465311674, st_mtime=1465311674, st_ctime=1465311685)
>>> os.stat("/mnt/my_network_drive/COMPLETED/sample.xml")
posix.stat_result(st_mode=33272, st_ino=4913809333, st_dev=25L, st_nlink=1, st_uid=1000, st_gid=0, st_size=10, st_atime=1465317482, st_mtime=1465317482, st_ctime=1465317483)
>>> os.path.islink("/mnt/my_network_drive/somewhere/sample.xml")
False
>>> os.path.islink("/mnt/my_network_drive/COMPLETED/sample.xml")
False
>>> shutil._samefile("/mnt/my_network_dive/somewhere/sample.xml", "/mnt/my_network_drive/COMPLETED/sample.xml")
False
As you see, calling shutil._samefile
I get False
but shutil.copy
still raise the samefile error
.
Am I forgetting something? Any other way to move or copy files with Python?