blob: b05874bfb7e18419fceea4afa06b6d3bf7402255 [file] [log] [blame]
Kaido Kert5ac52c42021-05-14 12:23:37 -07001#!/usr/bin/env python3
2#
3# Copyright 2014 The Chromium Authors. All rights reserved.
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
10from __future__ import print_function
11
12import fnmatch
13import optparse
14import os
15import sys
16
17
18def main(argv):
19 parser = optparse.OptionParser()
20 parser.add_option('--pattern', default='*', help='File pattern to match.')
21 options, directories = parser.parse_args(argv)
22
23 for d in directories:
24 if not os.path.exists(d):
25 print('%s does not exist' % d, file=sys.stderr)
26 return 1
27 for root, _, filenames in os.walk(d):
28 for f in fnmatch.filter(filenames, options.pattern):
29 print(os.path.join(root, f))
30
31
32if __name__ == '__main__':
33 sys.exit(main(sys.argv[1:]))