我有一个文件夹,其中有586 excel文件与.xls和.xlsx格式,然后我使用shutil和我转移文件到目标,如下面的代码。你知道吗
import shutil
import glob
for filename in glob.glob('C:\\Users\\Documents\\sample_folder\\**\\**', recursive=True):
if filename.endswith('.xlsx') or filename.endswith('.xls'):
shutil.copy(filename,"C:\\Users\\Documents\\excel-files")
事情进展顺利,398个文件成功地传输到目标,但我没有得到剩余的文件,它显示了一个错误,如
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 121, in copyfile with open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: 'C:\Users\Documents\excel-files\XYZ 1310_template.xlsx'
考虑使用
shutil.copyfile(src, dst)
而不是shutil.copy()
,因为您拥有写入所有文件的权限。让我知道这是否有效。你知道吗否则,请检查您是否具有写入指定文件的权限,尝试在没有
XYZ 1310_template.xlsx
文件的情况下运行程序,并查看这是否是唯一无法工作的文件。你知道吗更多的提示可以在documentary中找到 或者that post早些时候问过。你知道吗
我很确定你的shutil(部分代码不是正确的方法)。你知道吗
相关问题 更多 >
编程相关推荐