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
Published on 27-Dec-2017 08:07:21
Advertisements