In this article we will show very simple examples of how to move, and delete files in Python using the built-in functions such as shutil.move(), and os.remove(). Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating the process of copying and removal of files and directories.
Moving Files in Python
import shutil, os Files = ['FileA.txt', 'FileB.txt', 'FileC.txt'] for F in Files: shutil.move(F, 'dest_folder')
Deleting Files in Python
To delete a file, you must import the OS module, and run its os.remove() function:
import os
os.remove("Example.txt")