python - Traceback(最近一次调用最后一次):(无法复制树“%s”:不是目录”% src)
问题描述
我想使用 python 编写一个小脚本,该脚本进入我的谷歌驱动器文件夹并将那里的所有文件复制到具有当前日期的文件夹中。所以 fromDirectory 显然是我的程序应该从中复制文件的目录,而 todirectory 是外部硬盘上的目录。我已经检查了路径是否正确,并且我确定它们是正确的。不幸的是,出现了一个错误:
Traceback (most recent call last):
File "C:\Users\Michael\Desktop\test.py", line 13, in <module>
copy_tree(fromDirectory, toDirectory)
File "C:\Users\Michael\AppData\Local\Programs\Python\Python37\lib\distutils\dir_util.py", line 124, in copy_tree
"cannot copy tree '%s': not a directory" % src)
distutils.errors.DistutilsFileError: cannot copy tree 'C:/Users/Michael/Desktop/Google Drive': not a directory
代码:
import time
import sys
import shutil
from distutils.dir_util import copy_tree
import os
from datetime import datetime
today = datetime.now()
fromDirectory = "C:/Users/Micheal/Desktop/Google Drive"
toDirectory = "S:/" + today.strftime('%d%m%Y')
copy_tree(fromDirectory, toDirectory)
希望得到帮助!
编辑: 我很愚蠢:
我在 PC1 上编写了我的程序,现在在 PC2 上对其进行了测试,所以我没有注意到 PC1 的桌面上确实有一个 Google Drive 文件夹,但在 PC2 的桌面上却没有(只是 Google Drive 文件夹的快捷方式)。对于 PC2,正确的路径是“C:/Users/Michael/Google Drive”。
解决方案
问题可能出' '
在“Google Drive”中,尝试将其重命名为“Google_Drive”或“Google-Drive”。您也可以尝试替换"C:/Users/Micheal/Desktop/Google Drive"
为"C:/Users/Micheal/Desktop/'Google Drive'"
,因为这就是它在 bash 脚本中的工作方式,但我不能保证在这种情况下它会工作
编辑:您还可以\
在空格前添加一个,因此Google Drive
变为Google\ Drive
.
推荐阅读
- java - 如何验证带有冒号限制的字符串
- python - Django Rest 框架响应
- python - 使用 TCP 进行套接字编程三向握手 (PYTHON)
- amazon-ecs - 如何在容器环境变量的 ECS 任务定义中设置机密?
- amazon-s3 - 如何使用 aws cli 阻止对我的所有存储桶的公共访问?
- javascript - 我应该如何使用 javascript 过滤 JSON?
- python - Selenium 找不到类
- excel - 加快/改进此 VBA 脚本的建议?
- reactjs - 如何为简单的 Fulcro 应用程序设置动态 UI 路由
- html - 如果隐藏了该广告,则不支持通过该广告设置的 HTML 列宽