Skip to content

Instantly share code, notes, and snippets.

@sblack4
Created August 26, 2021 15:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sblack4/b5e001c84a561e7490add1d2f9a332f3 to your computer and use it in GitHub Desktop.
Save sblack4/b5e001c84a561e7490add1d2f9a332f3 to your computer and use it in GitHub Desktop.
Crawls through files and provides hooks to process name or contents
#!/usr/bin/env python3
import glob
import os.path
root_dir = ''
def filename_hook(filename):
print(filename)
def filetxt_hook(filetxt):
print(filetxt)
for filename in glob.iglob(root_dir + '**/**', recursive=True):
filename_hook(filename)
if not os.path.isfile(filename):
print(f'ERROR file doesnt exist: {filename}')
continue
with open(filename, 'r') as fh:
file_text = fh.readlines()
filetxt_hook(file_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment