File "/root/createfile.py", line 15, in <module> with open(os.path.join(file,'file'+str(k)),'w') as NR: FileNotFoundError: [Errno 2] No such file or directory: '/root/python/file00/file00'
时间: 2024-04-12 19:29:25 浏览: 14
这个错误是由于文件的路径不存在导致的。根据错误信息可以看出,文件`'/root/python/file00/file00'`的路径不存在。
请确保你的目标目录`/root/python`存在,并且具有创建文件的权限。你可以手动创建该目录,或者在代码中添加创建目录的逻辑,如下所示:
```python
import os
import shutil
folder_path = '/root/python'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
for i in range(20):
k = '%02d' % i
file = os.path.join(folder_path, 'file' + str(k))
with open(os.path.join(file, 'file' + str(k)), 'w') as NR:
NR.write('file' + str(k))
```
这样修改后,如果目录`/root/python`不存在,代码会先创建该目录,然后再创建文件。请确保你有足够的权限来执行这些操作。