anmittal | 2a43fe2 | 2016-08-18 04:36:25 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
mtklein | b91f756 | 2015-05-16 15:47:10 -0700 | [diff] [blame] | 3 | # Copyright 2015 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | ''' |
mtklein | ada5a44 | 2016-08-02 14:28:26 -0700 | [diff] [blame] | 9 | find.py is a poor-man's emulation of `find -name=$1 $2` on Unix. |
mtklein | b91f756 | 2015-05-16 15:47:10 -0700 | [diff] [blame] | 10 | |
mtklein | ada5a44 | 2016-08-02 14:28:26 -0700 | [diff] [blame] | 11 | Call python find.py <glob> <directory>... to list all files matching glob under |
mtklein | b91f756 | 2015-05-16 15:47:10 -0700 | [diff] [blame] | 12 | directory (recursively). E.g. |
mtklein | ada5a44 | 2016-08-02 14:28:26 -0700 | [diff] [blame] | 13 | $ python find.py '*.cpp' ../tests/ ../bench/ |
| 14 | will print all .cpp files under ../tests/ and ../bench/. |
mtklein | b91f756 | 2015-05-16 15:47:10 -0700 | [diff] [blame] | 15 | ''' |
| 16 | |
| 17 | import fnmatch |
| 18 | import os |
| 19 | import sys |
| 20 | |
mtklein | ada5a44 | 2016-08-02 14:28:26 -0700 | [diff] [blame] | 21 | for directory in sys.argv[2:]: |
| 22 | for d, kids, files in os.walk(directory): |
| 23 | files.sort() |
| 24 | for f in files: |
| 25 | if fnmatch.fnmatch(f, sys.argv[1]): |
| 26 | print os.path.join(d, f).replace('\\', '/') # Gyp wants Unix paths. |