10 examples of 'python check if folder exists' in Python

Every line of 'python check if folder exists' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
58def check_folder(folder):
59 if not os.path.exists(folder):
60 try:
61 os.makedirs(folder)
62 except OSError as e:
63 if e.errno != errno.EEXIST:
64 raise
65 return True
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

21def check_dir(folder):
22 # Check if a folder already exists, if not return the value True.
23 import os
24 import sys
25
26 if os.path.exists(folder):
27 if not os.listdir(folder):
28 return False
29 else:
30 print('Folder: <%s> already exists. Program aborted.' % folder)
31 sys.exit()
32 else:
33 return True
200def check_folder():
201 if not os.path.exists("data/badges"):
202 os.makedirs("data/badges")
203 if not os.path.exists("data/badges/temp"):
204 os.makedirs("data/badges/temp")
205 if not os.path.exists("data/badges/temp/tempgif"):
206 os.makedirs("data/badges/temp/tempgif")
156def check_folders():
157 if not os.path.exists('data/picwelcome/'):
158 os.mkdir('data/picwelcome/')
142def exists(env):
143 for version in versions:
144 if get_winddk_root(env, version) is not None:
145 return True
146 return False
262def path_check(path):
263 if os.path.exists(path):
264 return True
265 else:
266 return False
48@staticmethod
49def _file_exists(path):
50 return os.path.isfile(path)
21def exists(name):
22 if os.sep in name:
23 variants = [name]
24 else:
25 variants = [os.path.join(dir, name) for dir in PATH]
26 for path in variants:
27 if os.path.isfile(path) or os.path.isfile(path + exe_suffix):
28 return True
29 return False
22def create_folder(folder):
23 """ Create folders to retrieve posters and thumbnails
24 """
25 print(folder)
26 if not os.path.exists(folder):
27 os.makedirs(folder)
16def check_exists():
17 ses = []
18 for i in range(5):
19 if os.path.exists(f"./temp/servant{i}.png") == 1:
20 ses.append(i)
21 print("ses:", ses)
22 return ses

Related snippets