This post will discuss how to move all files from a directory to another directory in Python.

1. Using shutil.move() function

You can use the shutil module to move files within the same or different file systems. To move a file, shutil has the move() function. It calls the os.rename() function when the destination is on the same disk as the source; otherwise, it copies the source file to the destination and then deletes it.

Download Code

2. Using os.rename() function

Another solution is to use the os.rename() function for moving all files from a directory to another directory within a file system. This is demonstrated below:

Download Code

 
The os.rename() can be used when the destination is on the same disk as the source. However, it raises an exception when the file already exists in the destination. If you want to overwrite the destination file, use os.replace().

Download Code

That’s all about moving all files from a directory to another directory in Python.