10 examples of 'python get folders in directory' in Python

Every line of 'python get folders in directory' 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
155@staticmethod
156def get_dir_folders(dirpath):
157 contents = []
158 for i in os.listdir(dirpath):
159 # drop hidden
160 if i[0] == '.':
161 continue
162 filepath = os.path.join(dirpath,i)
163 is_dir = os.path.isdir(filepath)
164 if is_dir:
165 filepath = filepath + '/'
166 else:
167 continue
168 contents.append( ( i,filepath,is_dir ) )
169 contents.sort(key=lambda tup: tup[1])
170 return contents
11def get_file_list(folder):
12 file_list = []
13 for root, dirs, files in os.walk(folder):
14 for ff in files:
15 file_list.append(ff)
16 return file_list
31def list_folder_contents():
32 folder_contents = {}
33 for root, dirs, files in os.walk(KINDLE_EBOOKS_ROOT):
34 for f in [get_relative_path(os.path.join(root, el))
35 for el in files
36 if os.path.splitext(el.lower())[1] in SUPPORTED_EXTENSIONS]:
37 # if not directly in KINDLE_EBOOKS_ROOT
38 if get_relative_path(root) != u"":
39 folder_contents[f] = [get_relative_path(root)]
40 return folder_contents
122def get_file_list(folder):
123 files = list()
124 for d in os.listdir(folder):
125 files.extend(os.path.join(d, f) for f in os.listdir(os.path.join(folder, d)))
126 return sorted(files)
31def get_file_names(folder_path, hidden=False):
32 ret = None
33 if os.path.exists(folder_path):
34 ret = []
35 for sub_name in os.listdir(folder_path):
36 sub_path = os.path.join(folder_path, sub_name)
37 if ((hidden or sub_name[:1]!=".") and
38 (os.path.isfile(sub_path))):
39 ret.append(sub_name)
40 return ret
14def _get_sub_dirs(parent):
15 """Returns a list of the child directories of the given parent directory"""
16 return [child for child in os.listdir(parent) if os.path.isdir(os.path.join(parent, child))]
18def get_folders():
19 '''
20 Get all sync folders
21 '''
22 res = requests.get('%s/folders' % config.SYNC_API_BASE_URL)
23 folders = res.json().get('data').get('folders')
24 return folders
144def get_path(folder_id):
145 return shell.SHGetFolderPath(0, folder_id, None, 0)
65def get_files(self, directory):
66 files = list()
67 for file in os.listdir(directory):
68 files.append(os.path.join(directory, file))
69 return files
9def _listdir(root):
10 ''' List directory 'root' appending the path separator to subdirs. '''
11 res = []
12 for name in os.listdir(root):
13 path = os.path.join(root, name)
14 if os.path.isdir(path):
15 name += os.sep
16 res.append(name)
17 return res

Related snippets