Is the file on the same file system as another file in python?

Is there an easy way to find out if a file is on the same file system as another file?

Next command:

import shutil shutil.move('filepatha', 'filepathb') 

will try to rename the file (if it is in the same file system), otherwise it will copy it and then disconnect.

I want to know before calling this command whether it will execute a fast or slow version, how to do it?

+4
source share
1 answer

Use os.stat (by file name) or os.fstat (in the file descriptor). The result of st_dev will be the device number. If they are in the same file system, they 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 
+10
source

Source: https://habr.com/ru/post/1285972/


All Articles