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?

3
  • Using Solid Explorer on an Android device is one option not yet mentioned in the answers. Connect your Google Drive, then go to the Drive folder, click the 3-dot menu button and select Properties. Let it scan and then go to the Content tab, which will list folders and files in descending size order. Posting as a comment since I don't have enough reputation to post answers.
    – Magnus
    Commented May 8, 2022 at 8:05
  • See also stackoverflow.com/q/67686128/315024
    – Walf
    Commented Sep 29, 2022 at 0:58
  • At least on macOS, DaisyDisk now supports adding cloud accounts (including Google Drive), and runs a detailed storage inventory of your account. I have used this app for years for my local drives, and had no idea it supported cloud accounts until I needed to do this recently, and was trying to point it at my Google Drive "File Stream" mount locally. I ended up noticing they had add the option to configure cloud accounts… Highly recommended!
    – levifig
    Commented Jul 15, 2023 at 13:03

8 Answers 8

44

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() && currentPath.length < 2000) {
        var nextF = fChildren.next();
        totalSize += AddFolderToReport(report, nextF, currentPath + nextF.getName() + "/", 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("Getting Folder Sizes, " + report.length + " processed...");
    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.

3
  • Worked on most of the folders, except for the one I'm really trying to determine the size of (my Swift Backup folder). I ran the script twice, and both times, the folder just shows a size of 0.
    – Max Well
    Commented Dec 23, 2023 at 13:29
  • @MaxWell Do you see the file in your Drive root titled "Folder Sizes Report Completed" / do you see the message from script "Report file was already created in your Drive's root folder, exiting."? If there are too many files in the folder, then it could have been not processed yet. Commented Feb 1 at 9:51
  • Yes, I tried it two or three times, made sure I waited until the process finished each time. it worked for other folders, just not the one I mentioned. guessing part of the process is timing out, possibly too many files to query, or something else along those lines.
    – Max Well
    Commented Feb 1 at 21:46
26
+500

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".

1
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

2
  • 39
    it shows only files not folder
    – shareef
    Commented Sep 14, 2016 at 10:30
  • 1
    In my case this number is about a quarter of actual size....
    – Mamrezo
    Commented May 16, 2021 at 10:05
17

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

11
  • /dataset didn't work for me. taking it out seem to work... the first 2 steps are quite confusing from my brief experience now trying to replicate them. waiting for at least 15 minutes for the task to complete or even reach any folder to show up.
    – cregox
    Commented Sep 12, 2020 at 16:59
  • 1
    well, it worked! now i hope we can find out a way to properly redirect the reward...
    – cregox
    Commented Sep 12, 2020 at 20:25
  • big caveat: it'll consider all kinds of files, regardless if it's counting against the quota or not. i don't think there's any way around it.
    – cregox
    Commented Sep 12, 2020 at 21:44
  • 1
    this is my favourite one liner, so far: ! cd /content/drive/My\ Drive/ ; du --apparent-size -csh * | sort -rh
    – cregox
    Commented Sep 13, 2020 at 8:25
  • Well, /content/drive/My\ Drive/ gives you access to the root folder of your drive.
    – Aditya
    Commented Sep 15, 2020 at 11:12
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.)

11
  • One would need to copy the contents in order to own the files, but that is infeasible if there are multiple folders inside the parent folder in question.
    – ahorn
    Commented Apr 30, 2019 at 4:30
  • @ahorn You can copy a folder with subdirectories in Drive.
    – Fiksdal
    Commented Apr 30, 2019 at 4:32
  • @Revetahw how does one do that? When I right-click a folder, there is no option to "Make a copy" as with files.
    – ahorn
    Commented Apr 30, 2019 at 15:14
  • 2
    @ahorn Wow, you're right
    – Fiksdal
    Commented May 1, 2019 at 3:24
  • 1
    @cregox Oh, so this app will stop its processing if you even switch to another app in the middle of the process? That is rather annoying, although I guess I did not notice since my process was so fast that I did not have time to switch to another app. I guess a decent solution would be to run this app on an Android emulator (or a virtualized Android-within-Android) so that the app thinks it is always in the foreground, even if you need to use your Android-device for something else while it is processing. That way the long processing time can be acceptable.
    – Fiksdal
    Commented Sep 6, 2020 at 19:51
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.

0
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.

2
  • 2
    The folders that I've selected for Google drive on my PC amount to >6 GB. However google drive website says they are only 3.7 GB (fully synched). Would be nice to check folder sizes/no files within etc as I'm not convinced all my files are synched!
    – user56353
    Commented Jan 5, 2014 at 11:51
  • 1
    @user56353 PCs will sometimes report the disk space used. Disk space is allocated in whole blocks, like 4k in size, and if a file is only 1k, it still uses 4k on disk. Thousands of small files could use up lots of wasted space. Google Drive might report only actual file size. Also Google Drive may compress photos & videos, or de-duplicate files between users if they are the same file. Check actual file size vs. size on disk. Windows 8.1 reports both in File Properties (ALT+ENTER).
    – Chloe
    Commented Sep 29, 2017 at 17:20
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!

1
  • For anyone wanting a more GUI solution, baobab - the standard ubuntu disk usage analysis tool works quite well with fuse mounted google drives.
    – Tejas Kale
    Commented Jun 4, 2021 at 10:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.