147

In Google Drive, you can use Sort split-button and choose Quota Used to show the size of each file there.

However, folder sizes are not shown.

I guess it's really a basic requirement in order to manage folders in Google Drive. I have a folder full of subfolders and files, and I can't go summing up the size of each file recursively.

I need to decide whether deleting this folder or not. But I need to know it's size beforehand.

Is there any way to see how much volume a folder has taken?

Rubén - Volunteer Moderator -
  • 46,305
  • 18
  • 101
  • 297
Saeed Neamati
  • 1,951
  • 3
  • 18
  • 19

8 Answers8

45

The script will create two files in the root of your Drive, one displays progress and is deleted after script is completed. Other is the report which lists all folders and sizes. It looks like this.Google Drive folder sizes report

(if it gets stopped because of execution time limit, just run it once again, and it will continue from where it left)

Copy and paste the code into Google Script editor and run doGet() function from there:

function doGet() {
    var progressFileCompletedFound = DriveApp.getRootFolder().searchFiles("title contains 'Folder Sizes Report Completed'");
    if (progressFileCompletedFound.hasNext()) {
        return ContentService.createTextOutput("Report file was already created in your Drive's root folder, exiting.");
    }
    CreateReportFile();
    DriveApp.createFile("Folder Sizes Report Completed.txt", "You may safely delete this file.");
    return ContentService.createTextOutput("Report file created in your Drive's root folder");
}

function CreateReportFile() { var reportContent = CreateReport(); DriveApp.createFile('Folder Sizes Report.txt', reportContent); }

function CreateReport() { var reportContent = ""; var progressFileFound = DriveApp.getRootFolder().searchFiles("title contains 'Getting Folder Sizes,'"); var progressFile; var report = []; if (progressFileFound.hasNext()) { progressFile = progressFileFound.next(); var json = progressFile.getBlob().getDataAsString(); try { report = JSON.parse(json); } catch(Exception) { DriveApp.removeFile(progressFile); progressFile = DriveApp.createFile("Getting Folder Sizes, 0 processed...", " "); } } else { progressFile = DriveApp.createFile("Getting Folder Sizes, 0 processed...", " "); } var f = DriveApp.getRootFolder(); AddFolderToReport(report, f, "/", progressFile); DriveApp.removeFile(progressFile); reportContent += "TotalSize MB FilesSize MB Path \r\n"; for (var i = 0; i < report.length; i++) reportContent += Utilities.formatString("%12.2f ", (report[i].totalSize / (1024 * 1024))) + Utilities.formatString("%11.2f ", (report[i].filesSize / (1024 * 1024))) + report[i].folderPath + "\r\n"; return reportContent; }

function AddFolderToReport(report, currentFolder, currentPath, progressFile) { var report1 = []; for (var i = 0; i < report.length; i++) if (report[i].folderPath == currentPath) return report[i].totalSize;

var fChildren = currentFolder.getFolders();
var totalSize = 0;
while (fChildren.hasNext() &amp;&amp; currentPath.length &lt; 2000) {
    var nextF = fChildren.next();
    totalSize += AddFolderToReport(report, nextF, currentPath + nextF.getName() + &quot;/&quot;, progressFile);
}
var filesSize = 0;
var files = currentFolder.getFiles();
while (files.hasNext()) {
    filesSize += files.next().getSize();
}
totalSize += filesSize;
report.push({folderPath: currentPath, filesSize: filesSize, totalSize: totalSize});
progressFile.setName(&quot;Getting Folder Sizes, &quot; + report.length + &quot; processed...&quot;);
progressFile.setContent(JSON.stringify(report));
return totalSize;

}

As Google now blocks unverified scripts, the only way to use it is copy-paste the source to your script editor (previously it was enough to just click a link). And verification requires some extra effort, so I didn't do it yet.

alexkovelsky
  • 561
  • 4
  • 6
27

You can use Python. This answer was inspired by Aditya, so please upvote his answer there. I provide improved code below, which can display only the largest folders. (It is my first time coding in Python!)

In Google Colab, create a new notebook, click on the "Files" icon in the left sidebar, and "Mount Drive". You will need to authenticate the Google Drive File Stream to access your Google account, and copy the authentication token into the Colab notebook.

Then, run this code:

import re
all = open("all.txt", "w")
! du -h /content/drive/My\ Drive/* >> all.txt
all.close()
GB = open("GB.txt", "w")
for line in open("all.txt", "r"):
    if re.search("G\t", line):
        GB.write(line)
        print(line)
GB.close()

All the folder sizes will be saved in "all.txt". Note that the -h option (as opposed to -sh) displays sub-folders. Then, "G\t" is the string which is searched for (a capital G, followed by a tab), and that line is printed. That isolates the folders which are at least 1GB large. (You could use "M\t" for folders with a megabyte size.) These largest folders are stored in "GB.txt".

ahorn
  • 2,218
  • 1
  • 17
  • 35
22

Update 2020

Nowadays, clicking on n GB of nn GB used takes us to the list of biggest files on our Drive:

end update



Not by folders but great to find where are the big files, thanks to this pretty hat tip: Sort your Google Drive Files by Size to Find the Biggest Files.

On GDrive left panel, hover Upgrade storage:

where to click

Now click that i at the right of Drive, and there we have it:

showing biggest files This is the direct link for that: https://drive.google.com/drive/quota

brasofilo
  • 410
  • 5
  • 16
18

One approach to this is using Google Colab.

Step 1: Visit Google Colab and create a new python 3 notebook.

Step 2: Mount drive by running this code in a cell:

from google.colab import drive
drive._mount('/content/drive')

This will provide you an url to obtain an authorization code, which you will need to provide in a box.

Step 3: run this code in the cell: (replace folder-name with any folder in your drive)

! du -sh /content/drive/My\ Drive/<folder-name>

For example, to get the total size of the /content/drive/My\ Drive/dataset directory, you would run the following command:

! du -sh /content/drive/My\ Drive/dataset

Output: 3.4G /content/drive/My Drive/dataset

if you want to display the disk usage of the first-level subdirectories, run:

! du -sh /content/drive/My\ Drive/dataset/*

Output: 24K /dataset/db 3.3G /dataset/lib 4.0K /dataset/local 108.0M /dataset/lock 856.0M /dataset/log

For more details on du command, visit: https://linuxize.com/post/how-get-size-of-file-directory-linux/

Edit: drive.mount has been changed to drive._mount

Niklas
  • 3
  • 1
Aditya
  • 319
  • 3
  • 7
5

Update, september 2020:

There is now an Android app that can do this for you, called Storage Analyzer & Disk Usage,

It gives you a detailed tree of the entire folder hirearchy, just like WinDirStat on Windows or (KDirStat on GNU/Linux or Disk Inventory X on macOS).

This is what it looked like when I ran it:

enter image description here

If you do not have access to an Android device, there are many Android emulators for desktop and even in-browser ones (proceed with caution on the latter, as you will have to sign in with your Google-account on a system you do not have control over.)

Beware: Apparently this app has a design flaw, it will need to be in the foreground constantly while it runs its analysis (which can take some time if your Google Drive folder has a lot of content.)

Fiksdal
  • 638
  • 2
  • 7
  • 20
5

I was also looking for way to list folder and file sizes so that I can do clean up on my Google Drive. I actually found quite an accurate way of doing it.

  • Download and install Google Drive for Desktop from Google
  • After installation, sign into your Google account using the Drive Drive for Desktop.
  • It'll add your Google Drive as a drive on your device with Windows. enter image description here
  • Download and install WinDirStat
  • Open WinDirStat and then select the network storage unit added by Google Drive for Desktop.
  • Scan the drive, and viola. It even shows the date and time of the last change enter image description here

Credits go to Brenda Dann 9525 for introducing me to Drive File Stream: Brenda's reply, Dec 4, 2020, to How to check for folder size in google drive | Google Drive Help Community. Drive for Desktop replaced File Drive Stream. As of November 2023, it serves the same purpose.

Rubén - Volunteer Moderator -
  • 46,305
  • 18
  • 101
  • 297
Shaun Kleyn
  • 51
  • 1
  • 2
3

If you use Linux,

  1. Mount your Google Drive account as a network drive on your computer, using the google-drive-ocamlfuse package (in Alessandro Strada's PPA). Note: the files will not be downloaded (unless you open them), so this method won't use much of your data allowance.

  2. Save the folder hierarchy, with sizes, as a text file. I recommend you only inspect the folders bigger than 1GiB, as that makes it easier to find the biggest folders (in case you want to reduce disk space):

    cd "/home/username/Google-Drive"     # (or wherever the drive is mounted)

    tree --du -h | grep G] > "tree.txt"

    where you may want to be more specific about where the .txt file is stored.

    Note: be patient with the tree command. If you have a lot in storage, it will take a while.

  3. Print out the text file, inspect and enjoy!

ahorn
  • 2,218
  • 1
  • 17
  • 35
3

If you have Google Drive installed on your PC or MAC, use Windows Explorer (PC) or Finder (MAC) to easily check the folder sizes. I could not find a way to do it from a web browser.

mm32993
  • 47
  • 1