鱼C论坛

 找回密码
 立即注册
查看: 2265|回复: 2

[已解决]文件复制问题

[复制链接]
发表于 2021-7-4 22:32:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import os, shutil
  2. import re

  3. p = re.compile(r'(.*?)\.txt')
  4. for foldername, subfolders, filenames in os.walk('D:/Python/Fluentoython'):
  5.     print(f"The current folder is {foldername}.")
  6.     for subfolder in subfolders:
  7.         print(f"The subfolder of {foldername} is {subfolder}.")
  8.     for filename in filenames:
  9.         print(f"The filename of {foldername} is {filename}")
  10.         mo = p.search(filename)
  11.         # print(mo.group())
  12.         ps = os.path.join(mo.group(), foldername)
  13.         shutil.copy(ps, 'D:/Python/new_move')
  14. for filenames in os.walk('D:/Python/new_move'):
  15.     print(filenames, end='\t')
复制代码


这是我想把一个文件里的所有文本文档复制到另外一个文件夹的程序。
但是运行提示:    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'D:/Python/Fluentoython'
是什么权限问题,哪位前辈帮忙解决一下?谢谢
最佳答案
2021-7-4 23:27:26
多看看文档:
shutil.copy(src, dst, *, follow_symlinks=True)
Copies the file src to the file or directory dst.  ....


shutil.copy()  只能复制文件,不能复制文件夹。
复制文件夹用 shutil.copytree()

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-7-4 23:27:26 | 显示全部楼层    本楼为最佳答案   
多看看文档:
shutil.copy(src, dst, *, follow_symlinks=True)
Copies the file src to the file or directory dst.  ....


shutil.copy()  只能复制文件,不能复制文件夹。
复制文件夹用 shutil.copytree()

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-7-5 09:55:02 | 显示全部楼层

谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 15:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表