-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
autof.py
29 lines (27 loc) · 927 Bytes
/
autof.py
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
import os
import sys
import re
def autoscan(pathdir):
filelist = None
parentdir = os.path.realpath(os.path.join(pathdir, '..'))
for root, dirs, files in os.walk(pathdir, topdown=False):
for name in files:
rx = re.compile(r'\.(cfg|lua)$', re.I)
m = re.search(rx, name)
if m:
value = os.path.realpath(os.path.join(root, name))
value = value [ len(parentdir) +1 : ]
if os.name == "posix":
value = re.sub(r'^\/', '', value)
else:
value = re.sub(r'^(?:[A-Za-z]\:)?\\', '', value)
if filelist is None:
filelist = [ value ]
else:
filelist.append(value)
# end if m
# end for name
# end for root
# end for scandir
return (parentdir, filelist)
# end autoscan