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.


import shutil

Demonstrations of Shutil Module

which() show the directory

>>> import shutil
>>> shutil.which("python")
>>> shutil.which("python3")

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\\","D:\\")

Copy() to copy the file

>>>import shutil
>>> shutil.copy("C:\\Users\\ASUS\\Desktop\\test.txt","D:\\")

rmtree() to delete the from directory

>>> import shutil
>>> shutil.rmtree("C:\\Users\\ASUS\\Desktop\\test")
Subscribe Now