How to check file size in Python? Last Updated : 17 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisites: osĀ pathlib Given a file, the task here is to generate a Python Script to print its size. This article explains 2 methods to do so. ApproachImport moduleGet file sizeFile in use Name: Data.csv Size: 226 bytes Method1: Using pathlib Path().stat().st_size() function of pathlib module gets the size of any type of the file and the output of this function will be the size of the file in bytes. Syntax: Path('filename').stat().st_size() Example: Python3 from pathlib import Path sz = Path('Data.csv').stat().st_size print(sz) Output: Method 2: With Os module os.path.getsize() function only works with os Library, with the help of importing this library we can use this to get the size of any type of file and the output of this function will be the size of the file in bytes. Syntax: getsize(filename) Example: Python3 import os sz = os.path.getsize("Data.csv") print(sz) Output: We got the result as 226 bytes Comment More infoAdvertise with us Next Article How to get file size in Python? G geetansh044 Follow Improve Article Tags : Python python-file-handling Python file-handling-programs Practice Tags : python Similar Reads How to get file size in Python? We can follow different approaches to get the file size in Python. It's important to get the file size in Python to monitor file size or in case of ordering files in the directory according to file size. Method 1: Using getsize function of os.path module This function takes a file path as an argume 3 min read How to find size of an object in Python? In python, the usage of sys.getsizeof() can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object in bytes. It takes at most two arguments i.e Object itself. Note: Only the memory consumption directly attributed t 2 min read How to get size of folder using Python? In this article, we are going to discuss various approaches to get the size of a folder using python. To get the size of a directory, the user has to walk through the whole folder and add the size of each file present in that folder and will show the total size of the folder. Steps to be followed: 3 min read How to delete data from file in Python When data is no longer needed, itâs important to free up space for more relevant information. Python's file handling capabilities allow us to manage files easily, whether it's deleting entire files, clearing contents or removing specific data.For more on file handling, check out:File Handling in Pyt 3 min read How to Check the Size of a Directory in Linux Many times during working on Linux we may encounter situations, where we want to check the total size occupied by a directory, especially when working with large files and directories. Knowing the file or directory size can help a user perform tasks like storage allocation, size comparison, etc. At 7 min read Python - How to Check if a file or directory exists Sometimes it's necessary to verify whether a dictionary or file exists. This is because you might want to make sure the file is available before loading it, or you might want to prevent overwriting an already-existing file. In this tutorial, we will cover an important concept of file handling in Pyt 5 min read Like