Glob pattern to read in a specific string in Python

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’)… Read More Glob pattern to read in a specific string in Python

how to read specific JSON files using python glob

i have a set of JSON files in a folder. Sample files: -2022_06_13_07_14_f71cd512135bdab9.json -2022_06_13_07_1421_f71cd512135bdab9.json -2022_06_13_07_12314_f71cd512135bdab9.json -2022_06_14_132_14_f71cd512135bdab9.json -2022_06_14_74647_14_f71cd512135bdab9.json Instead of reading all files at once, I need to read them day-wise. ex:2022_06_13_07_14_f71cd512135bdab9.json corresponding to 2022_06_13. like wise I need to read all the JSON files and do the changes in Daywise batches. read all JSON files… Read More how to read specific JSON files using python glob

return found path in glob

If I have a glob(‘path/to/my/**/*.json’, recursive = True), function returns something like: path/to/my/subfolder1/subfolder2/file1.json path/to/my/subfolder1/subfolder2/file2.json path/to/my/subfolder1/subfolder2/file3.json path/to/my/subfolder1/file4.json path/to/my/file5.json … I’d like to get only part that starts after ** in the glob, so subfolder1/subfolder2/file1.json subfolder1/subfolder2/file2.json subfolder1/subfolder2/file3.json subfolder1/file4.json file5.json … What is the best way to do it? Does glob support it natively? Glob input is provided… Read More return found path in glob

glob finds the same file 10 times

Why does the recursive=True lead to finding the same file 10 times. >>> for g in glob.glob("/home/result/test/**/**/**/*.xml", recursive=True): … if "testsystems" in g: … print(f"{g}") … /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml According to the docs I expected to need to use recursive=True to support **. If recursive is true, the… Read More glob finds the same file 10 times