您的位置:首页 > 编程语言 > Python开发

python实现批量移动TXT文件到指定目录

2018-11-16 14:34 736 查看
import os
import os.path
from shutil import copy

for dirpath,dirnames,filenames in os.walk(r"C:\work\I2P\workspace\testdata2"):
for filename in filenames:
if os.path.splitext(filename)[1] == ".txt":
filepath = os.path.join(dirpath,filename)

copy(filepath,r"C:\Users\Administrator\Desktop\卫星类型\\"+filename)

遇到的问题:
(unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

在字符串前加上 r"C:\Users\Administrator\Desktop\卫星类型\" r即可

EOL while scanning string literal

在C:\Users\Administrator\Desktop\卫星类型\ 路径名后面不能使用 单斜杠 需要使用双斜杠

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: