Shutil Module
In this tutorial we learn about the shutil library,it gives the facilitated operation over the file and it is the very essential module of python .
What is Shutil Module
The shutil Module offers several functions to deal with the files and their collections,it provides full control over the file.
Syntax
import shutil shutil.submodule_name(arguments)
Demonstrations of Shutil Module
which() show the directory
>>> import shutil >>> shutil.which("python") 'C:\\Users\\ASUS\\AppData\\Local\\Programs\\Python\\Python38-32\\python.EXE' >>> shutil.which("python3") 'C:\\Users\\ASUS\\AppData\\Local\\Microsoft\\WindowsApps\\python3.EXE
move() to move a file
Below is the program we use move() to relocate a file one to another destination.
>>>import shutil >>> shutil.move("C:\\Users\\ASUS\\Desktop\\test.py","D:\\") 'D:\\test.py' >>>
Copy() to copy the file
>>>import shutil >>> shutil.copy("C:\\Users\\ASUS\\Desktop\\test.txt","D:\\") 'D:\\test.txt' >>>
rmtree() to delete the from directory
>>> import shutil >>> shutil.rmtree("C:\\Users\\ASUS\\Desktop\\test") >>>