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

PythonServer Side ProgrammingProgramming

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
raja
Updated on 16-Dec-2019 06:28:25

Advertisements