Is there a simple way of finding out if a file is on the same filesystem as another file?
The following command:
import shutil
shutil.move('filepatha', 'filepathb')
will try and rename the file (if it's on the same filesystem), otherwise it will copy it, then unlink.
I want to find out before calling this command whether it will preform the quick or slow option, how do I do this?
Use os.stat
(on a filename) or os.fstat
(on a file descriptor). The st_dev
of the result will be the device number. If they are on the same file system, it will be the same in both.
import os
def same_fs(file1, file2):
dev1 = os.stat(file1).st_dev
dev2 = os.stat(file2).st_dev
return dev1 == dev2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With