Try the pathlibpathlib package instead:
>>> from pathlib import Path >>> Path() WindowsPath('.') >>> Path().absolute() WindowsPath('C:/Users/p00200284/test') >>> Path().absolute().parent WindowsPath('C:/Users/p00200284') >>> Path().absolute().parent / "all_files.tex" WindowsPath('C:/Users/p00200284/all_files.tex') >>> str(Path().absolute().parent / "all_files.tex") 'C:\\Users\\p00200284\\all_files.tex' >>> Path().absolute().parent.name 'p00200284' >>> f"{Path().absolute().parent.name}_all_files.tex" 'p00200284_all_files.tex' >>> parent_dir = Path().absolute().parent >>> parent_dir / f"{Path().absolute().parent.name}_all_files.tex" WindowsPath('C:/Users/p00200284/p00200284_all_files.tex')