If you collect first all files in a list, then you have to classify them all afterwards by country and year.
A different approach is to scan the directories, to acquire the information and then return pairwise the files.
A different approach is to scan the directories, to acquire the information and then return pairwise the files.
from pathlib import Path from pprint import pprint def easier_grouping(root): root = Path(root) for year in root.iterdir(): if year.is_dir() and year.name.isdecimal(): for country in year.iterdir(): ics_root = country / "ICS" xls_file = ics_root / "Work" / f"{country.name} profile inflation {year.name}.xls" xlsm_file = ics_root / f"{country.name}_taxcheck_{year.name[-2:]}.xlsm" if xls_file.exists() and xlsm_file.exists(): yield xls_file, xlsm_file pprint(dict(easier_grouping("Tax scripts")), indent=4)
Output:{ WindowsPath('Tax scripts/2020/Germany/ICS/Work/Germany profile inflation 2020.xls'): WindowsPath('Tax scripts/2020/Germany/ICS/Germany_taxcheck_20.xlsm'),
WindowsPath('Tax scripts/2020/Hungary/ICS/Work/Hungary profile inflation 2020.xls'): WindowsPath('Tax scripts/2020/Hungary/ICS/Hungary_taxcheck_20.xlsm')}
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!