This script scans a specified directory and its subdirectories for files larger than a specified size and prints their paths and sizes in a human-readable format.
- Python 3.6+
osmodule (standard library)humanizemodule
-
Clone or download this repository.
-
Install the required
humanizemodule if you don't have it already:
pip install humanize-
Open the script file (
large_file_scanner.py) in a text editor. -
Modify the
min_sizeandpathvariables in theif __name__ == "__main__":block to suit your needs:min_size: The minimum file size to look for, specified in megabytes (MB). The default is set to 2048 MB (2 GB).path: The directory path to scan. The default is set toC:\\(the C drive on Windows). Change this to the drive or directory you want to scan.
if __name__ == "__main__": min_size = 2048 * 1024 * 1024 # This is the size in MB path = "C:\\" # Change this to the directory you want to scan
-
Save the changes and run the script:
python large_file_scanner.py- The script will output the number of large files found and list them with their paths and sizes.
Scanning for large files...
Found 5 files larger than 2.0 GB:
C:\path\to\largefile1: 2.1 GB
C:\path\to\largefile2: 2.5 GB
...
The script handles FileNotFoundError and PermissionError exceptions that may occur during file size retrieval. If these errors are encountered, the script will skip the problematic files and continue scanning.
Feel free to open issues or submit pull requests if you have suggestions or improvements.