|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os, shutil
- import re
- p = re.compile(r'(.*?)\.txt')
- for foldername, subfolders, filenames in os.walk('D:/Python/Fluentoython'):
- print(f"The current folder is {foldername}.")
- for subfolder in subfolders:
- print(f"The subfolder of {foldername} is {subfolder}.")
- for filename in filenames:
- print(f"The filename of {foldername} is {filename}")
- mo = p.search(filename)
- # print(mo.group())
- ps = os.path.join(mo.group(), foldername)
- shutil.copy(ps, 'D:/Python/new_move')
- for filenames in os.walk('D:/Python/new_move'):
- print(filenames, end='\t')
复制代码
这是我想把一个文件里的所有文本文档复制到另外一个文件夹的程序。
但是运行提示: with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'D:/Python/Fluentoython'
是什么权限问题,哪位前辈帮忙解决一下?谢谢
多看看文档:
shutil.copy(src, dst, *, follow_symlinks=True)
Copies the file src to the file or directory dst. ....
shutil.copy() 只能复制文件,不能复制文件夹。
复制文件夹用 shutil.copytree()
|
|