python - 使用 python shutil 库移动文件
问题描述
我正在尝试使用 Pythonshutil
库在闪存驱动器内的文件目录中移动特定文件夹。我收到以下错误:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\New Folder\\CN00020'.
我查看了一些发布的问题,我认为我的问题可能是我没有正确声明文件路径。我正在使用适用于 Python 和 Windows 10 的 Spyder 应用程序。
import shutil
shutil.move('D:\\New Folder\CN00020', 'D:\\Batch Upload')
解决方案
问题是它\
具有特殊含义。Python 解释\C
为特殊字符。有三种解决方案:
# escape backspace
shutil.move('D:\\New Folder\\CN00020', 'D:\\Batch Upload')
# use raw strings
shutil.move(r'D:\New Folder\CN00020', r'D:\Batch Upload')
# use forward slashes which shutil happens to support
shutil.move('D:/New Folder/CN00020', 'D:/Batch Upload')
推荐阅读
- plesk - 部落注册禁用
- c# - org.apache.solr.common.SolrException:搜索请求无法接受 Solr4 中的内容流
- excel - 我可以在 Excel 的数据透视表中选择 2 个字段作为索引吗?
- javascript - CSS:使用类名切换类时出错
- angular - 将图像 FILE_URI 转换为 Base64 字符串?
- excel - 数据模型中的数据透视表问题
- python - 不清楚的python实例方法(增量type())
- python-pptx - add_picture() 文件格式
- visual-c++ - 使用 ENSURE 避免代码分析警告的最佳替代方法是什么?
- java - 用 Intent 在浏览器中打开 Base64