To check whether the file or folder exists, we need to interact with the OS filesystem. Python made it easy by providing the “os” module. It provides the functionality to interact with the operating systems.

Just import “os.path” module and with that, we can access the file system and check whether the file or folder is present.

To check if the path(folder or file) is present

import os.path<br>os.path.exists(folder_or_file_path)

To check if the file is present

import os.path<br>os.path.isfile(file_path)

 

Categorized in:

Tagged in: