Skip to content

Instantly share code, notes, and snippets.

@Thomas-Moore-Creative
Created June 9, 2021 07:36
Show Gist options
  • Save Thomas-Moore-Creative/ccc3e217162a27e3782a460d89376823 to your computer and use it in GitHub Desktop.
Save Thomas-Moore-Creative/ccc3e217162a27e3782a460d89376823 to your computer and use it in GitHub Desktop.
generate file list using regex
import re
file_list =[]
# get regex range from web generator - https://3widgets.com/
# find range of files from filename_1981.nc to filename_2018.nc
regexp = re.compile('filename_(198[1-9]|199[0-9]|200[0-9]|201[0-8]).nc')
ROOT_DIR ='/root/path/to/files/'
for root, dirs, files in os.walk(ROOT_DIR):
for file in files:
if regexp.search(file):
file_list.append(os.path.join(root, file))
file_list.sort()
file_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment