我正在尝试使用Python将文件从一个文件夹移动到另一个文件夹。我试过使用shutil,os.replace,os.rename,但是每次遇到TypeError时都会遇到相同的错误:move()缺少1个必需的位置参数:'dst'在此处输入图像描述
这是我的代码的一段(为了避免显示敏感信息而模棱两可):
import os
import shutil
filename = f"fileNamePlaceholder"
directory = f"originalFileLocation"
destination = f"newFileLocation"
shutil.move(f'"{directory}{filename}","{destination}"')
很基本,但是我得到TypeError:move()每次都缺少1个必需的位置参数:“ dst”错误。我尝试将输出粘贴到命令行,它确实可以工作并移动文件,但是当我尝试直接运行它时,出现了错误。我也尝试过os库来移动文件,但是也有'dst'错误。这应该是非常基本的,但是我无法使其正常工作。
注意:我正在Linux Bash Shell中使用Windows 10。
注意您的报价,您的中只有一个参数shutil.move()
:
你写了: shutil.move(f'"{directory}{filename}","{destination}"')
应该 shutil.move(f"{directory}{filename}",f"{destination}")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句