-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearcher.py
More file actions
executable file
·37 lines (31 loc) · 1.19 KB
/
searcher.py
File metadata and controls
executable file
·37 lines (31 loc) · 1.19 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
#!/usr/bin/env python3
"""Routines for searching files and folders.
This module is part of Patrick Mooney's Python utility scripts. These scripts
are licensed under the GNU GPL, either version 3 or (at your option) any later
version. See the file LICENSE.md for details.
"""
import os
def get_files_list(which_dir, skips=None):
"""Get a complete list of all files and folders under WHICH_DIR, except those matching SKIPS.
Calls itself recursively, so it's a bad idea if the directory is (literally)
very profound.
"""
if skips == None:
skips = [][:]
ret = [][:]
for (thisdir, dirshere, fileshere) in os.walk(which_dir):
ret.append(os.path.join(thisdir))
if dirshere:
for dname in dirshere:
ret += get_files_list(os.path.join(thisdir, dname), skips)
if fileshere:
for fname in fileshere:
ret.append(os.path.join(thisdir, fname))
if skips:
for the_skip in skips:
ret = [the_item for the_item in ret if the_skip not in the_item]
ret.sort()
return ret
if __name__ == "__main__":
from pprint import pprint
pprint(get_files_list('.', None))