Skip to content

Commit 2dad334

Browse files
committed
use os.walk for listing files and folder
1 parent 1e2a414 commit 2dad334

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

cactus/utils/filesystem.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ def fileList(paths, relative=False, folders=False):
1919

2020
files = []
2121

22-
for path in paths:
23-
for fileName in os.listdir(path):
24-
25-
if fileName.startswith('.'):
26-
continue
27-
28-
filePath = os.path.join(path, fileName)
29-
30-
if os.path.isdir(filePath):
31-
if folders:
32-
files.append(filePath)
33-
files += fileList(filePath)
34-
else:
35-
files.append(filePath)
22+
def append(directory, name):
23+
if not name.startswith('.'):
24+
path = os.path.join(directory, name)
25+
files.append(path)
3626

27+
for path in paths:
28+
for directory, dirnames, filenames in os.walk(path, followlinks=True):
29+
if folders:
30+
for dirname in dirnames:
31+
append(directory, dirname)
32+
for filename in filenames:
33+
append(directory, filename)
3734
if relative:
3835
files = map_apply(lambda x: x[len(path) + 1:], files)
3936

0 commit comments

Comments
 (0)