License New BSD license
Lines 26
Keywords
file (4) suffix (1)
Permissions
Viewable by Everyone
Editable by All Siafoo Users
Hide
Don't get spied on – We respect your privacy and provide numerous options to protect it. Join Siafoo Now or Learn More

Get Files With Suffixes Atom Feed 0

In Brief Finds all files under a path with given suffixes.
# 's
 1# Copyright 2007 Regents of the University of California
2# Written by David Isaacson at the University of California, Davis
3# BSD License
4
5import os
6
7def getFilesBySuffix(path, suffixes):
8 successes = []
9 if os.path.isdir(path):
10 os.path.walk(path, checkSuffixes, [successes, suffixes])
11 elif os.path.isfile(path):
12 for suffix in suffixes:
13 if path.endswith("." + suffix):
14 successes.append(path)
15 break
16 return successes
17
18def checkSuffixes(array, path, files):
19 '''Helper function for getFilesBySuffix, called by os.path.walk'''
20 successes, suffixes = array;
21 for file in files:
22 if suffixes:
23 for suffix in suffixes:
24 suffix = "." + suffix;
25 if file.endswith(suffix):
26 successes.append(os.path.join(path, file))
27 break
28 else:
29 successes.append(os.path.join(path, file))

Finds all files under a path with given suffixes.