如果文件夹 2 不包含该文件,则将文件从文件夹 1 移动到文件夹 2

Move files from folder 1 to folder 2 if the folder 2 does not contain the file

如果文件夹 2 不包含文件,我需要编写 python 代码将文件从一个文件夹(文件夹 1)移动到另一个文件夹(文件夹 2)。我想知道我们是否应该使用 shutil.copy

试试这个

if not os.path.exists('destination path'):
    shutil.move("path/to/current/file.foo",
                "path/to/new/destination/for/file.foo")