find.py (767B)
1 #!/usr/bin/env python3 2 # 3 # Copyright 2014 The Chromium Authors 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 7 """Finds files in directories. 8 """ 9 10 11 import fnmatch 12 import optparse 13 import os 14 import sys 15 16 17 def main(argv): 18 parser = optparse.OptionParser() 19 parser.add_option('--pattern', default='*', help='File pattern to match.') 20 options, directories = parser.parse_args(argv) 21 22 for d in directories: 23 if not os.path.exists(d): 24 print('%s does not exist' % d, file=sys.stderr) 25 return 1 26 for root, _, filenames in os.walk(d): 27 for f in fnmatch.filter(filenames, options.pattern): 28 print(os.path.join(root, f)) 29 return 0 30 31 32 if __name__ == '__main__': 33 sys.exit(main(sys.argv[1:]))