Python | os.path.isfile() method
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name manipulation.
os.path.isfile() method in Python is used to check whether the specified path is an existing regular file or not.
Syntax: os.path.isfile(path)
Parameter:
path: A path-like object representing a file system path. A path-like object is either a string or bytes object representing a path.Return Type: This method returns a Boolean value of class bool. This method returns True if specified path is an existing regular file, otherwise returns False.
Code #1: Use of os.path.isfile() method
# Python program to explain os.path.isfile() method # importing os module import os # Path path = '/home/User/Desktop/file.txt' # Check whether the # specified path is # an existing file isFile = os.path.isfile(path) print(isFile) # Path path = '/home/User/Desktop/' # Check whether the # specified path is # an existing file isFile = os.path.isfile(path) print(isFile) |
True False
Reference: https://docs.python.org/3/library/os.path.html
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.scandir() method
- Python | cmath.log() method
- Python | os.ctermid() method
- Python | os.getppid() method
- Python | Tensorflow abs() method
- Python | cmath.exp() method
- Python | os.strerror() method
- Python | sys.getrecursionlimit() method
- Python | os.readv() method
- Python | Tensorflow log() method
- Python | os.writev() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet




