Computer >> Computer tutorials >  >> Programming >> Python

How to check if a file is a directory or a regular file in Python?


You can check if a file is a directory or a file using the os.path.isfile method:

Example

>>> import os
>>> print os.path.isfile('my_file.txt')
True
>>> print os.path.isfile('my_folder')
False