Kaido Kert | 5ac52c4 | 2021-05-14 12:23:37 -0700 | [diff] [blame] | 1 | #!/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 | |
| 10 | from __future__ import print_function |
| 11 | |
| 12 | import fnmatch |
| 13 | import optparse |
| 14 | import os |
| 15 | import sys |
| 16 | |
| 17 | |
| 18 | def 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 | |
| 32 | if __name__ == '__main__': |
| 33 | sys.exit(main(sys.argv[1:])) |