If you run automated backups, sync log files, or work with data export scripts, Google Drive can quickly turn into a dumping ground. Last week, while cleaning up some folder structures, I found thousands of stray .txt files scattered across subfolders. Clicking them one by one in the web browser was out of the question—unless I wanted my weekend stolen away from my kids and my retro gaming setup.
Manually deleting files through the Google Drive web interface works fine for five or ten files. But when you hit hundreds or thousands, the web app starts lagging, selecting all items fails to load, and your browser tab might just crash.
Here are three practical ways to clean up those files safely, depending on how many files you have and how deep they are hidden.
Method 1: Search and Select All (Best for Quick Cleanup)
If your files live in a single folder or you just want to purge every text file across your entire Drive, the web search bar is actually pretty clever if you use the right filter.
- Open Google Drive in your browser.
- In the top search box, type:
Plaintexttype:textPro tip: If you only want to clear files inside a specific folder, open that folder first, click the Search options icon (the sliders on the right side of the search bar), set the Location to your current folder, and set Type to “Text documents”. - Click on the very first file in the search results list.
- Press
Ctrl + A(orCmd + Aon Mac) to highlight the files. - Press the
Deletekey or click the trash can icon at the top right. - Head over to Trash in the left sidebar and click Empty trash to reclaim your storage space.
Watch out for the browser limit: Google Drive only loads about 50 to 100 items at a time as you scroll down. If you press
Ctrl + Aright away, it will only select what is visible on the screen. Keep scrolling down to force Drive to load more items before selecting all.
Method 2: Use Google Drive for Desktop (Best for Sysadmins)
If you use Google Drive for Desktop on Windows or Mac, you can skip the browser entirely and let your local operating system handle the heavy lifting. This is my preferred approach when dealing with complex directory trees.
Once your drive is mounted locally, open your terminal or command prompt, navigate to your synced Drive folder, and run the matching command below:
Windows (Command Prompt):
DOS
del /s *.txt
Windows (PowerShell):
PowerShell
Get-ChildItem -Path . -Filter *.txt -Recurse | Remove-Item -Force
Linux / macOS:
Bash
find . -name "*.txt" -type f -delete
Why is this better? The OS handles recursive subfolder scanning much faster than a browser UI can render it. The local client will queue up the deletions and sync them back to the cloud in the background while you grab a coffee.
Method 3: Google Apps Script (Best for Massive/Automated Deletions)
What if you have 10,000+ text log files nested ten folders deep, and local syncing takes too long? We write a small script to run directly on Google’s cloud servers.
It takes less than two minutes to set up, and you don’t need to install anything on your machine.
- Head over to script.google.com and click New Project.
- Delete the default code and paste this script:
JavaScript
function deleteTxtFiles() {
// Replace with your target Folder ID (found in the folder URL after /folders/)
var folderId = "YOUR_FOLDER_ID_HERE";
var folder = DriveApp.getFolderById(folderId);
var files = folder.getFilesByType(MimeType.PLAIN_TEXT);
var count = 0;
while (files.hasNext()) {
var file = files.next();
file.setTrashed(true); // Safely moves file to Trash instead of permanent delete
count++;
}
Logger.log("Moved " + count + " .txt files to Trash.");
}
- Get your Folder ID: Open the target folder in Google Drive, look at the browser URL bar, and copy the long string of letters and numbers after
folders/. - Paste that ID into
YOUR_FOLDER_ID_HEREin the script. - Click Save (floppy disk icon), then click Run.
Safety Check: Notice that the script uses
file.setTrashed(true)instead of hard deleting the file. This sends everything to your Google Drive Trash first. If you made a mistake or wiped out an important configuration file, you can restore it with one click.
Which Method Should You Choose?
- Under 200 files in one spot? Use Method 1 (Search bar). Fast and easy.
- Files scattered across complex local folders? Use Method 2 (Terminal). Let your CLI handle recursive subdirectories.
- Thousands of files purely in the cloud? Use Method 3 (Apps Script). It lets Google’s backend do the grinding so your computer doesn’t lag.
Got stuck or running into permission errors on shared drives? Drop a comment below or reach out on CrushEdge. Happy fixing!
No Comments