Search code examples
pythoncopypython-os

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


I need to write python code to move a file from one folder (Folder 1 )to another (Folder 2) if the folder 2 does not contain the file. I want to know if we should use shutil.copy


Solution

  • try this out

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