os.rename vs shutil.move

Moving files in Python

import os

import shutil

shutil.move('file.txt', 'path/to/new/directory/')

While, in principle, both os.rename() and shutil.move() can be used to move files, shutil.moves() attempts to overcome limitations of os.rename() for the task of moving files.

Use shutil.moves() for moving files on disk!

shutil.moves() handling is closer to mv command

os.rename() requires to include the file name in both the source and destination arguments ('rename' !)

os.rename('path/to/file.txt', 'path/to/new/directory/file.txt')

while shutil.move() requires only the new directory as destination ('move' !)

shutil.move('path/to/file.txt', 'path/to/new/directory/')

shutil.moves() supports different disk drives

If source and destination are on a different hard disks, shutil.move() first copies the source to destination and then removes the source.