Skip to content

Instantly share code, notes, and snippets.

@h4ndzdatm0ld
Last active November 17, 2020 05:59
Show Gist options
  • Save h4ndzdatm0ld/38a8733c376d85506ae0afb2c8d35f04 to your computer and use it in GitHub Desktop.
Save h4ndzdatm0ld/38a8733c376d85506ae0afb2c8d35f04 to your computer and use it in GitHub Desktop.
globfindfile #glob,file,find
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