-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (24 loc) · 913 Bytes
/
Copy pathutils.py
File metadata and controls
32 lines (24 loc) · 913 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
28
29
30
31
32
import os
def get_py_files(path):
# print out os path file and directory
print(f"Is file? {os.path.isfile(path)}")
print(f"Is dir? {os.path.isdir(path)}")
py_files = []
# check if file- ends with .py, ez pz
if os.path.isfile(path) and path.endswith('.py'):
py_files.append(path)
elif os.path.isdir(path): # if folder
# walking paths, appending full paths
### all subdirectories '_.'
### BFS type stuff
for root, _, files in os.walk(path):
for file in files:
if file.endswith('.py'):
# grabs all paths, connecting to root
full_path = os.path.join(root, file)
# slaps em into py_files
py_files.append(full_path)
else:
# nyop
print(f"Invalid path: {path}")
return py_files