Identify empty folders in Google Drive

This article will discuss how to identify empty folders in Google Drive.

Identify empty folders in Google Drive

The best way to do this is, via a script. Say you must find the empty folders and then delete them. You can follow the below steps.

  1. Open Google sheet.
  2. Click on the Tools menu –> Then click on the Script editor as highlighted below.
How To Find Empty Folders In Google drive

3. In the code editor window paste the below code.

function deeteEmptyFolders() {

var myfolders = DriveApp.getFolders();

var xy = SpreadsheetApp.create("FolderDetails");

while (myfolders.hasNext()) {

var folder = myfolders.next();

var myfiles = folder.getFiles();

var childfolders = folder.getFolders();

var filecount = 0;

var foldercount = 0;

while (childfolders.hasNext()){

var childfolder = childfolders.next();

foldercount ++;

}

while (myfiles.hasNext()){

var file = myfiles.next();

filecount ++;

}

xy.appendRow([folder.getId(),folder.getName(),filecount, foldercount]);

if (filecount == 0 && foldercount == 0){

folder.setTrashed(true);

}

}

}

4. Click the Save button and then the Run button as highlighted below.

How To Find and delete Empty Folders In Google drive

5. Now, you will get the expected output.

Find and delete Empty Folders In Google drive

You may also like following the articles below

Wrapping Up

In this article, we discussed the quick ways to identify empty folders in Google Drive. Thanks for reading this article !!!