我有一个包含几个pdf和word文件的文件夹。我想创建一个新文件夹,在此文件夹中,我要根据之前阅读的文件创建子文件夹,每个子文件夹应包含3个空白文本文件,例如test1。 txt,test2.txt,test.txt我是python新手,请帮忙。...
from pathlib import Path
files = Path().iterdir()
for file in files:
new_file_path = Path(f'./{file.stem}')
new_file_path.mkdir(parents=True, exist_ok=True)
for i in range(3):
p = Path(f'./{file.stem}') / f'{i}.txt'
with p.open('w') as nf:
nf.write('')