python-3.x - Python:PermissionError:[Errno 13] 与 windows 中的 copy_tree 函数
问题描述
我只是使用 Windows 中的函数 distutils.dir_util.copy_tree 从特定目录复制所有文件和子文件夹:
from distutils.dir_util import copy_tree
from datetime import datetime
directories_to_backup = {
'folder_a' : 'e:\\folder_a',
}
now = datetime.now()
backup_name_folder = now.strftime("%Y%m%d-%H%M")
for name_folder, path_folder in directories_to_backup.items():
print(f'Backuping up the folder {name_folder}')
backup_full_path = f't:\\zzzBackup\\{backup_name_folder}\\{name_folder}\\'
copy_tree(path_folder, backup_full_path)
它工作正常,直到它到达某个特定文件并出现以下错误:
Traceback (most recent call last):
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\file_util.py", line 48, in _copy_file_contents
buf = fsrc.read(buffer_size)
PermissionError: [Errno 13] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/UserR/PycharmProjects/my_scripts/main_backup.py", line 28, in <module>
copy_tree(path_folder, backup_full_path)
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 159, in copy_tree
verbose=verbose, dry_run=dry_run))
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 159, in copy_tree
verbose=verbose, dry_run=dry_run))
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 159, in copy_tree
verbose=verbose, dry_run=dry_run))
[Previous line repeated 1 more times]
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 163, in copy_tree
dry_run=dry_run)
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\file_util.py", line 151, in copy_file
_copy_file_contents(src, dst)
File "C:\Users\UserR\AppData\Local\Programs\Python\Python37\lib\distutils\file_util.py", line 51, in _copy_file_contents
"could not read from '%s': %s" % (src, e.strerror))
distutils.errors.DistutilsFileError: could not read from 'e:\folder_a\0\binlog': Permission denied
Process finished with exit code 1
如何更新 Windows 中的权限,以便我的脚本能够读取和复制文件?
解决方案
推荐阅读
- java - SFTP 默认会话工厂或 SFTP 普通连接,用于将文件上传到多个远程服务器
- python - 如何使用 python 和 selenium webdriver 更改下载位置
- html - 如何显示存储在mongodb字段中的html代码
- javascript - 在 Angular 中编写可链接函数的正确方法是什么?
- javascript - 窗口重新加载到相同位置后,固定标题不会保持固定
- reactjs - 如何在反应中循环嵌套数组?
- node.js - 如何创建自定义命令实用程序
- sql - 更换桌子的最佳方法
- vtiger - 非管理员用户无法访问报告
- javascript - jquery getjson成功功能不起作用