os.path.samefile() in Python is used to check if the specified two paths refer to the same file or directory or not. This is determined by comparing the device number and the i-node number of the given paths.
This method uses
os.stat () b> exception if any
os.stat () call
os.stat () will fail for any of the paths.
Syntax: os.path.samefile (path1, path2)
path1 : A path-like object representing the first file system path.
path2 : A path-like object representing the second file system path. p>
A path-like object is either a string or bytes object representing a path.
Return Type : This method returns a Boolean value of class bool. This method returns True if both path refer to the same file otherwise returns False.
Code: Using the os.path.samefile () method to check if specified paths to the same file or directory.