python 移动文件报错,路径有转义字符

有水印需要去除水印
有水印需要去除水印
有水印需要去除水印
watermark is get over
此时的文件夹为/home/shenjianlin/pdf_file/宏观固收中期策略报告:寻找阿尔法,经济新.pdf


Traceback (most recent call last):
  File "/usr/lib64/python3.4/shutil.py", line 527, in move
    os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/home/shenjianlin/pdf_file/宏观固收中期策略报告:寻找阿尔法,经济新.pdf' -> 'home/shenjianlin/pdf_file/trash_pdf_file'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "remove_water_mark.py", line 89, in <module>
    remove_water_mark().read_content()
  File "remove_water_mark.py", line 78, in read_content
    shutil.move(file, self.trash_pdf_path)
  File "/usr/lib64/python3.4/shutil.py", line 539, in move
    copy2(src, real_dst)
  File "/usr/lib64/python3.4/shutil.py", line 245, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib64/python3.4/shutil.py", line 108, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/home/shenjianlin/pdf_file/宏观固收中期策略报告:寻找阿尔法,经济新.pdf'

这里的转义字符如何处理,因为是for 循环文件夹的 无法用‘r’,都是用变量存的文件名

阅读 2.5k
1 个回答

请把代码提上来一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题