Last active
November 17, 2020 05:59
-
-
Save h4ndzdatm0ld/38a8733c376d85506ae0afb2c8d35f04 to your computer and use it in GitHub Desktop.
globfindfile #glob,file,find
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def globfindfile(regex): | |
''' This function will simply locate a file in the DIR by passing the directory/regex value (ie:(*.log)) | |
The returned value by calling the function is the file. | |
''' | |
try: | |
if len(glob.glob(regex)) == 0: | |
sys.exit(f"No {regex} file found.") | |
else: | |
for file in glob.glob(regex): | |
if len(glob.glob(regex)) > 1: | |
sys.exit(f"Err.. found too many {regex} files") | |
else: | |
# print(f"Found a configuration file: {file}\n") | |
return file | |
except Exception as e: | |
print(f"Something went wrong, {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment