python中shutil是什么意思,很多关于shutil的错误,说文件在Python中时不存在
以下是我的所有代码:import shutil
import glob
import os
for filename in glob.glob(r"C:/Users/Aydan/Desktop/RTHPython/Years/*.txt"):
text_file_name = filename.strip()
dst = (os.path.join(r"C:/Users/Aydan/Desktop/SortedImages", text_file_name))
with open (text_file_name) as my_file:
for filename in my_file:
file_name = filename.strip()
src = (os.path.join('C:/Users/Aydan/Desktop', file_name))
src = src.replace('/', '\\')
shutil.move(src, dst)
循环{I>在每个文件中循环}每行文本。文本文件中的每一行都有一个文件目录:
^{pr2}$
此文件目录用作使用shutil的文件源,目标是不带.txt的文本文件的名称,即1855和1856。这意味着1855以下的文件进入1855文件夹,1856年也一样。在
不过,我还是会继续收到这些代码的错误,但我不明白为什么:Traceback (most recent call last):
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 544, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:/Users/Aydan/Desktop/data01/BL/ER/D11/fmp000005578/BL_ER_D11_fmp000005578_0001_1.txt' -> 'C:\\Users\\Aydan\\Desktop\\RTHPython\\Years\\1855.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 8, in
shutil.move(src, dst)
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 558, in move
copy_function(src, real_dst)
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Aydan/Desktop/data01/BL/ER/D11/fmp000005578/BL_ER_D11_fmp000005578_0001_1.txt'
>>>
即使它说No such file or directory:,我知道它就在那里,因为当我粘贴到它有错误的确切目录时,文本文件就会打开。。。在
我将非常感谢你的帮助来解决这个问题,并完成这个项目:D
谢谢!在
艾丹。在
更新代码:import shutil
import glob
import os
for filename in glob.glob(r"C:/Users/Aydan/Desktop/RTHPython/Years/*.txt"):
text_file_name = filename.strip()
dst = (os.path.join(r"C:/Users/Aydan/Desktop/SortedImages", text_file_name))
with open (text_file_name) as my_file:
for filename in my_file:
file_name = filename.strip()
src = (os.path.join('C:/Users/Aydan/Desktop', file_name))
src = src.replace('/', '\\')
shutil.move(src, dst)
这是新的错误:Traceback (most recent call last):
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 544, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\data01\\BL\\ER\\D11\\fmp000005578\\BL_ER_D11_fmp000005578_0001_1.txt' -> 'C:/Users/Aydan/Desktop/RTHPython/Years\\1855.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 9, in
shutil.move(src, dst)
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 558, in move
copy_function(src, real_dst)
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Aydan\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\data01\\BL\\ER\\D11\\fmp000005578\\BL_ER_D11_fmp000005578_0001_1.txt'
python中shutil是什么意思,很多关于shutil的错误,说文件在Python中时不存在相关推荐
- 编写程序,在文件file1.dat中存入字符串“good morning”,然后将file1.dat中的内容输出到屏幕上,并复制到文件file2.dat中
<程序设计基础-c语言>杨莉 刘鸿翔 ISBN-978-7-03-032903-5 p257 习题8 7.编写程序,在文件file1.dat中存入字符串"good morning ...
- word文档中找不到服务器,【在WORD文件中插入excel表格,编辑保存后重新打开word文件并双击excel时提示“找不到服务器应用程序、源文件】excel整个表格不见了...
为什么PPT插入EXCEL表格时显示无法找到服务器应用程序 这是由于excel或者ppt只能兼容.低版本的ppt和excel是无法打版本excel插入的表格的. 解决如下: 1.新建一个文本,将后缀名 ...
- python编辑elif显示错误_Python运行的17个时新手常见错误小结
1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 "SyntaxError :invalid syntax" ...
- Python文件格式详解:py、pyc、pyo、pyd文件区别
Python文件格式详解:py.pyc.pyo.pyd文件区别 Python是一种非常流行的编程语言,它具有简洁.易学.高效等优势,在各个领域得到了广泛的应用.而在Python编写程序时,我们会发现存 ...
- python中shutil是什么意思_python之shutil模块详解
-- --High-level file operations 高级的文件操作模块. os模块提供了对目录或者文件的新建/删除/查看文件属性,还提供了对文件以及目录的路径操作.比如说:绝对路径,父目 ...
- python shutil模块用法实例分析_Python shutil模块用法实例分析
分享大神指教Python中的shutil模块的rmtree()方法如分享大神指教Python中的shutil模块的rmtree()方法如何实现.思路是怎样的rmtree() 是用来删除文件目录及其中的 ...
- python中csv文件操作_python中操作csv文件
python中操作csv文件 读取csv improt csv f = csv.reader(open("文件路径","r")) for i in f: pri ...
- python一直报缩进错误_如何避免Python中的缩进错误
Python是当今编程界领先和新兴的编程平台之一.凭借其丰富的功能和巨大的灵活性,人们可以在这个平台上实现很多,只要他们知道如何操作它.在Python中的这个缩进错误中,我们将介 Python是当今编 ...
- python进阶书籍的推荐 知乎-知乎看了很多推荐,最终选了这本Python入门
Python 是军刀型的开源工具,被广泛应用于Web 开发.爬虫.数据清洗.自然语言处理.机器学习和人工智能等方面,而且Python 的语法简洁易读,这让许多编程入门者不再望而却步,因此Python ...
最新文章
- linux利用* vim提权,linux 通过suid vim.basic文件提权
- MAT入门到精通(二)
- 原生js路由跳转方法_今日艰难笔记原生js整合reactrouter路由管理
- Codeforces Round #696
- AUTOSAR专业知识篇(七)-比亚迪汉ECU接口
- 208. 实现 Trie (前缀树)
- 忧心文案小程序第二版前端后端源码
- shell 如何避免误删目录
- mondrian olap 示例_详解OLAP概念、基本内容、特点、分类
- 【程序员面试宝典】递归之两个字符串连接次序问题(P83)
- 《Macbook Pro概要》- Mac的各种功能使用方法
- swift 项目_谷歌为何要养苹果的亲儿子Swift?原来意在可微分编程
- Create umbraco website-On the road of umbraco (1)
- MySQL(17)-----数值函数
- hadoop系列-hadoop版本选择
- 【PMP】变更流程图与说明
- Django Hello,Word!(Windows10)
- gazebo可以另存为world
- idea项目名称重命名
- hdu2859 Phalanx(线性dp)