Check the existence of the file with python

import os
path = "./sample"

os.path.exists(path)

Now you can see the existence of a file or directory named sample.

By the way, if you want to check only the files without including the directory,

os.path.isfile(path)

If you don't want to include files and just want to see the directory

os.path.isdir(path)

Can be done with

Recommended Posts

Check the existence of the file with python
Check the date of the flag duty with Python
Convert the character code of the file with Python3
Extract the xz file with python
Existence from the viewpoint of Python
Check the scope of local variables with the Python locals function.
Check the behavior of destructor in Python
Let's read the RINEX file with Python ①
Check the path of the Python imported module
[Python] Get the character code of the file
Check the file size with du -sh *
[Python3] Understand the basics of file operations
The idea of feeding the config file with a python file instead of yaml
the zen of Python
Domain check with Python
Check version with python
[python] Check the elements of the list all, any
2016 The University of Tokyo Mathematics Solved with Python
[Note] Export the html of the site with python.
Calculate the total number of combinations with python
[Python] Summary of S3 file operations with boto3
[Python] Determine the type of iris with SVM
Get the update date of the Python memo file.
I made a program to check the size of a file in Python
Easy way to check the source of Python modules
Extract the table of image files with OneDrive & Python
Towards the retirement of Python2
Summary of python file operations
Learn Nim with Python (from the beginning of the year).
Download the file in Python
Check python coverage with pytest-cov
[Python] Get the official file path of the shortcut file (.lnk)
I tried to touch the CSV file with Python
Draw netCDF file with python
Existence check of external command in Python (like `which`)
Python --Check type of values
Destroy the intermediate expression of the sweep method with Python
About the ease of Python
Visualize the range of interpolation and extrapolation with python
Calculate the regression coefficient of simple regression analysis with python
Check OpenSSL version of python 2.6
Check for the existence of BigQuery tables in Java
Check the code with flake8
Summary of the basic flow of machine learning with Python
Call the API with python3.
Get the operation status of JR West with Python
About the features of Python
Download csv file with python
Extract the band information of raster data with python
Check the asymptotic nature of the probability distribution in Python
[Python] Check the installed libraries
The Power of Pandas: Python
I tried to find the entropy of the image with python
Try scraping the data of COVID-19 in Tokyo with Python
I tried "gamma correction" of the image with Python + OpenCV
Extract template of EML file saved from Thunderbird with python3.7
The story of implementing the popular Facebook Messenger Bot with python
Unify the environment of the Python development team starting with Poetry
Visualize the results of decision trees performed with Python scikit-learn
Check the operation of Python for .NET in each environment
Calculate the square root of 2 in millions of digits with python