Why os.move() Sometimes Does Not Work And Why shutil.move() Is The Savior?
Recently I ran into an issue where this, for example, code fails: import os os.rename('/foo/a.txt', '/bar/b.txt') Traceback (most recent call last): File "", line 1, in OSError: [Errno 18] Invalid cross-device link The documentation for the os module says that sometimes it might fail when the source and the destination are on different file-systems: os.rename( src, dst, *, src_dir_fd=None, dst_dir_fd=None) Rename the file or directory src to dst. If dst is a directory, OSError will be raised. On Unix, if dst exists and is a file, it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement). On Windows, if dst already exists, OSError will be raised even if it is a file. ...