xref: /aosp_15_r20/external/cronet/build/android/gyp/find.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
11import fnmatch
12import optparse
13import os
14import sys
15
16
17def 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
32if __name__ == '__main__':
33  sys.exit(main(sys.argv[1:]))
34