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