如题,如果a目录只有一个文件比较好办,只要通过制定文件名即可,比如:
a = open('b.py','w')
a.write('hallo world')
a.close
但是,如果a目录下不止一个文件,该如何批量最加内容呢?
错误啊。。。
Traceback (most recent call last):
File "", line 2, in
IOError: [Errno 13] Permission denied: 'DLLs'
首先,你要确保你对那些文件有读写的权限。
其次,要么你在那些文件所在文件夹运行这个脚本,要么改成:
import os
for i in os.listdir('目录名'):
p=os.path.join('目录名',i)
f=open(p,'a')
f.write('hello world')
f.close()
试了没效果啊。。。求解
求教具体步骤哇?