文件复制问题
import os, shutilimport 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: 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()
阿奇_o 发表于 2021-7-4 23:27
多看看文档:
谢谢
页:
[1]