0 points

Python: Check whether a file path is a file or a directory - w3resource


dashboard

Sat Oct 17 2020 16:14:28 GMT+0000 (UTC)

Posted by @arielvol #python

import os  
path="abc.txt"  
if os.path.isdir(path):  
    print("\nIt is a directory")  
elif os.path.isfile(path):  
    print("\nIt is a normal file")  
else:  
    print("It is a special file (socket, FIFO, device file)" )
print()


content_copy Copy

https://www.w3resource.com/python-exercises/python-basic-exercise-85.php