This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
The os.path.exists() method provided by the os standard library module returns True if a file exists, and False if not.
Here is how to use it:
import os
filename = '/Users/flavio/test.txt'
exists = os.path.exists(filename)
print(exists) # True
This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
flaviocopes.com | Sciencx (2021-01-25T05:00:00+00:00) Python, how to check if a file or directory exists. Retrieved from https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/
" » Python, how to check if a file or directory exists." flaviocopes.com | Sciencx - Monday January 25, 2021, https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/
HARVARDflaviocopes.com | Sciencx Monday January 25, 2021 » Python, how to check if a file or directory exists., viewed ,<https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/>
VANCOUVERflaviocopes.com | Sciencx - » Python, how to check if a file or directory exists. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/
CHICAGO" » Python, how to check if a file or directory exists." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/
IEEE" » Python, how to check if a file or directory exists." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/. [Accessed: ]
rf:citation » Python, how to check if a file or directory exists | flaviocopes.com | Sciencx | https://www.scien.cx/2021/01/25/python-how-to-check-if-a-file-or-directory-exists/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.