target_file_dir = os.path.join(target_dir, relative_path) target_file_path = os.path.join(target_file_dir, file.replace('.md', '.pdf')) ...