[Learning memo] Create if the directory does not exist / Get the files in the directory

If a directory does not exist in the python script, create that directory.

python


import os
if not os.path.isdir(dir):
    os.makedirs(dir)

Get all the file names in the directory in the python script.

python


import glob
all_file=glob.glob(dir+"/*")

Recommended Posts

[Learning memo] Create if the directory does not exist / Get the files in the directory
How to create a new file when the specified file does not exist — write if the file exists
python> does not include the letters mm> if "mm" not in text: / print "not including mm"
[Python] Get the files in a folder with Python
Pipfile is not created in the current directory
Access files in the same directory as the executable
How to get a list of files in the same directory with python
What to do if Python does not switch from the System version in pyenv
What to do if sys / cdefs.h does not exist
About the matter that nosetests does not pass when __init__.py is created in the project directory
Get and create nodes added and updated in the new version
Main configuration files introduced in the LPIC202 exam (personal memo)
When incrementing the value of a key that does not exist
Create a function to get the contents of the database in Go
Even if you cancel or delete the job in the queue, the process running on the worker does not stop.
Even if you cancel or delete the job in the queue, the process running on the worker does not stop (2)