import os
if not os.path.exists('my_folder'):
os.makedirs('my_folder')
import os
os.path.exists("file.txt") # Or folder, will return true or false
import os
print(os.path.isdir("/home/el"))
print(os.path.exists("/home/el/myfile.txt"))
import os.path
if os.path.isfile('filename.txt'):
print ("File exist")
else:
print ("File not exist")
>>> import os
>>> os.path.isdir('new_folder')
True
>>> os.path.exists(os.path.join(os.getcwd(), 'new_folder', 'file.txt'))
False