mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
26 lines
635 B
Python
Executable File
26 lines
635 B
Python
Executable File
#!/usr/bin/env python3
|
|
# Recursively find files matching a glob pattern. Replaces Unix (find) in lit tests
|
|
# for cross-platform compatibility
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def usage():
|
|
print("Usage: find_files <directory> <pattern>", file=sys.stderr)
|
|
sys.exit(2)
|
|
|
|
def main():
|
|
if len(sys.argv) != 3:
|
|
usage()
|
|
root, pattern = sys.argv[1], sys.argv[2]
|
|
p = Path(root)
|
|
if not p.exists():
|
|
print(f"Directory not found: {root}", file=sys.stderr)
|
|
sys.exit(2)
|
|
for x in p.rglob(pattern):
|
|
if x.is_file():
|
|
print(x)
|
|
sys.exit(0)
|
|
|
|
if __name__ == "__main__":
|
|
main() |