Created
June 9, 2021 07:36
-
-
Save Thomas-Moore-Creative/ccc3e217162a27e3782a460d89376823 to your computer and use it in GitHub Desktop.
generate file list using regex
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
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