0

我正在尝试使用 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() missing 1 required positional argument: 'dst' error 每次。我已经尝试将输出粘贴到命令行中,它确实可以工作并移动文件,但是当我尝试直接运行它时,我得到了错误。我也尝试过 os 库来移动文件,但也出现了“dst”错误。这应该是非常基本的,但我无法让它工作。

注意:我正在使用 Linux Bash Shell 中的 Windows 10。

4

1 回答 1

3

注意你的报价,你有一个单一的论点shutil.move()

你写了:shutil.move(f'"{directory}{filename}","{destination}"')

应该shutil.move(f"{directory}{filename}",f"{destination}")

于 2021-01-07T14:11:41.420 回答