Say I have an input file, and a target directory. How do I determine if the input file is on the same hard-drive (or partition) as the target directory?
What I want to do is the copy a file if it's on a different, but move it if it's the same. For example:
target_directory = "/Volumes/externalDrive/something/"
input_foldername, input_filename = os.path.split(input_file)
if same_partition(input_foldername, target_directory):
copy(input_file, target_directory)
else:
move(input_file, target_directory)
Thanks to CesarB's answer, the same_partition
function implemented:
import os
def same_partition(f1, f2):
return os.stat(f1).st_dev == os.stat(f2).st_dev