I have a folder with a list of files I want to read in as a list of full file paths.
The files that I want to read in have this structure: [0-9]_beta_[Y].nii.gz, where:
- [0-9] is a 3 digit sequence of numbers (e.g. 123)
- [Y] is a character string of any length (e.g. ‘faces’, ‘faces_up’)
What is the right pattern for this?
Here’s the code I have so far but it doesn’t get all the files I need:
file_list = glob.glob(os.path.join(data_dir, f'*_beta_*nii.gz'))
Thanks so much for your help!
>Solution :
Try:
file_list = glob.glob(os.path.join(data_dir, '[0-9][0-9][0-9]_beta_*.nii.gz'))
[0-9][0-9][0-9] matches exactly 3 digits, your * matches anything. And you should have . before nii.gz.
The string doesn’t need to be an f-string, you’re not substituting anything into it.