from pathlib import Path from os import fspath dest = r'C:\bar' with open('out1.txt', 'w') as f: for path in Path(dest).rglob('*'): if path.is_file(): print(path) f.write(f'{fspath(path)}\n')