Moving the data

Here, we will see how we can move the data. We will use shutil.move() for this purpose. shutil.move(source, destination) will move the file from source to destination. Now, we will create a shutil_move_example.py script and write the following content in it:

import shutil
shutil.move('/home/student/sample.txt', '/home/student/Desktop/.')

Run the script as follows:

$ python3 shutil_move_example.py

In this script, our file to move is sample.txt, which is in the /home/student directory. /home/student is our source folder and /home/student/Desktop is our destination folder. So, after running the script, sample.txt will be moved from /home/student to the /home/student/Desktop directory.