-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir_funcs.py
More file actions
27 lines (19 loc) · 749 Bytes
/
dir_funcs.py
File metadata and controls
27 lines (19 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Created 05-05-18 by Matt C. McCallum
A little module for inspecting directories.
"""
# Python standard library imports.
import os
def get_filenames(dirname, exts=['.wav', '.mp3']):
"""
Gets all filenames with a given extension in a directory.
Args:
dirname: str - A string containing the path to a directory to be analyzed.
exts: list(str) - A list of strings describing the extensions of all files to be returned.
Return:
list(str) - A list of paths to files that were found.
"""
all_files = os.listdir(dirname)
all_files = [fname for fname in all_files if os.path.splitext(fname)[1] in exts]
all_files = [os.path.join(dirname, fname) for fname in all_files]
return all_files