10 examples of 'get all file names in a folder python' in Python

Every line of 'get all file names in a folder python' 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
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
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

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
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 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
22def list_files(folder,ext_filter=None):
23 onlyfiles = []
24 for f in os.listdir(folder):
25 fullpath = os.path.join(folder, f)
26 if os.path.isfile(fullpath) and os.path.splitext(fullpath)[1]==ext_filter:
27 onlyfiles.append(fullpath)
28 return onlyfiles
40def get_file_names():
41 filenames = []
42
43 for folder, _, files in walk(icloudpath):
44 for filename in files:
45 filenames.append((folder + '/' + filename)[len(icloudpath) + 1:])
46
47 return filenames
2def getAllFiles(dir):
3 arry = []
4 for root, directories, filenames in os.walk(dir):
5 for filename in filenames:
6 arry.append(path.join(root,filename))
7
8 return arry
10def get_content_list(folder='.'):
11 """ Get list of contents in input folder
12
13 :param folder: input folder to list contents. Default is ``'.'``
14 :type folder: str
15 :return: list of folder contents
16 :rtype: list(str)
17 """
18 return os.listdir(folder)
33def get_file_list():
34 # Some stuff is too hard to package. just grab every file in these directories
35 # and call it a day. we can clean up some other time
36 pd_filelist = []
37 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'client')))
38 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'afe', 'doctests')))
39 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'afe', 'fixtures')))
40 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'afe', 'migrations')))
41 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'afe', 'templates')))
42 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'tko', 'fixtures')))
43 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'tko', 'migrations')))
44 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'tko', 'sql')))
45 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'static')))
46 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'templates')))
47 pd_filelist.extend(_get_files(os.path.join(fe_dir, 'tko', 'preconfigs')))
48 pd_filelist.extend([os.path.join(fe_dir, 'frontend.wsgi')])
49 return pd_filelist
30def _get_all_files():
31 paths = []
32 start_dir = os.getcwd()
33 pattern = "*.py"
34 for root, dirs, files in os.walk(start_dir):
35 globbed = glob(os.path.join(root, pattern))
36 paths.extend(globbed)
37 return paths

Related snippets