Python - check if a path is file or directory
To check whether given path is file or a directory we can use Python’s isdir() and isfile() functions. See below examples:
>>import os
>>given_path = “/home/rajan/
>>os.path.isdir(given_path)
True
>>os.path.isfile(given_path)
False
>>given_path2 = ‘/home/rajan/sample.txt’
>>os.path.isfile(given_path2)
True