This is a simple yet only known effective method to calculate google drive folder size using Python. Works for both gdrive file and folder. Uses Drive Api v3. It is scripted to be usable on terminal, the major application of this script is that you can use it on your gDrive projects by simply modifying it to your needs.
It returns a dict contains name, size, size in bytes, type, total number of files and total number of folders of the given gdrive file/folder's link/fileID.
The keys in the dict are name, size, bytes, type, files and folders.
pip3 install -r requirements.txt
- Create a
service
variable and pass it to the GoogleDriveSizeCalculate class. Notes to create it are given inside the bottom of the script. There you can either use a credentials.json or a service account to auth the service. python3 gdrive_calculator.py
- On the terminal, Input the url/fileid of your file/folder in Google Drive (Files associated with your account OR public shareable links Only)
Name: Smallville (2001-) Season 1-4 S01-S04
Size: 38.25GB
Type: Folder
Bytes: 41074136619
Files: 24
Folders: 5
If you want only size in bytes:
print(calculate['bytes'])