Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Finds files based on patterns (supporting wildcards *?[-])
- # Prints matching filenames or otherwise "NOT FOUND"
- # Exits with code 1 if at least one pattern doesn't match
- from __future__ import print_function
- import glob
- import sys
- import os
- pattern_list = ["LIP$DATE",
- "thefile.txt",
- "*$VAR1*",
- "*.py"]
- def replace_value(motif):
- motif = motif.replace("$DATE", "20190331")
- motif = motif.replace("$VAR1", "VALUE1")
- return motif
- def find_file(pattern):
- dirname = os.path.expanduser("~/data/read/")
- return glob.glob1(dirname, pattern)
- all_found = True
- for p in pattern_list:
- assigned_value = replace_value(p)
- matching_list = find_file(assigned_value)
- if len(matching_list) == 0:
- print("[%s]: NOT FOUND" % assigned_value, file=sys.stderr)
- all_found = False
- else:
- print("[%s]: %s" % (assigned_value, str(matching_list)))
- if all_found:
- sys.exit(0)
- else:
- sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement