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 process of copying and removal of files and directories.
shutil.disk_usage() method in Python is to get disk usage statistics about the given path. This method returns a named tuple with attributes total, used and free. The total attribute represents the amount of total space, the used attribute represents the amount of used space and the free attribute represents the amount of available space, in bytes.
Note: On Windows, the given path must represent a directory but on Unix systems, it can be a file or directory.
Syntax: shutil.disk_usage(path)
Parameter:
path: A path-like object representing a file system path. A path-like object is either a string or bytes object representing a path.
Return Type: This method returns a named tuple with attributed total, used and free.
# Python program to explain shutil.disk_usage() method # importing shutil module import shutil # Path path = "/home/User/Documents" # Get the disk usage statistics # about the given path stat = shutil.disk_usage(path) # Print disk usage statistics print("Disk usage statistics:") print(stat) |
Disk usage statistics: usage(total=244934381568, used=13350301696, free=219070689280)
Reference: https://docs.python.org/3/library/shutil.html
Recommended Posts:
- class method vs static method in Python
- Difference between Method Overloading and Method Overriding in Python
- Get() method for dictionaries in Python
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Line detection in python with OpenCV | Houghline method
- Python | os._exit() method
- Python | os.WEXITSTATUS() method
- Python | os.abort() method
- Python | os.renames() method
- Python | os.lseek() method
- Python calendar module | formatmonth() method
- Python | PyTorch sin() method
- Python | Sympy Line.is_parallel() method
- Python PIL | GaussianBlur() method
- Python | range() method
- Python | Numpy np.hermefit() method
- Python | Numpy np.hermevander() method
- Python String Title method
- Python groupby method to remove all consecutive duplicates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

