-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_utils.py
More file actions
38 lines (33 loc) · 1.14 KB
/
Copy pathbasic_utils.py
File metadata and controls
38 lines (33 loc) · 1.14 KB
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
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
"""
Basic utility functions for sequence analysis scripts
Ben Ober-Reynolds
"""
import os
def find_files_in_directory(dirPath, extensionList=None,
excludedExtensionList=None):
"""
Locate files in a given directory path. Optionally, desired files are
identified as matching one of the extension types provided in
'extensionList'
Input: directory path, list of approved extensions, (list of excluded
extensions)
Output: List of found files
"""
def extension_match(filename, extensionList=None):
# from CPlibs
if extensionList is not None:
for currExt in extensionList:
if filename.lower().endswith(currExt.lower()):
return True
return False
dirList = os.listdir(dirPath)
fileList = []
for currFilename in dirList:
if (extension_match(currFilename, extensionList)
and not extension_match(currFilename, excludedExtensionList)):
fileList.append(dirPath+currFilename)
if len(dirList) == 0:
print('\tNONE FOUND')
else:
return fileList