Get Trashed Files and Folders of Google Drive
Posted By: Harish

When we delete files stored in our google drive, they are not deleted completely. They are sent to the drive's trash bin and are stored for 30 days before deleting permanently(at the time of writing this post).
And these files are not calculated in the drive's used storage data as they will be deleted later.
So, even if we mistakenly delete stored drive data, we can retrieve them before completion of 30 days.
You can see the trashed files and folders by visiting Google Drive Trash Bin.
Get Google Drive Trash Bin files and folders
You can visit the trash bin page to check the files inside the bin.
But what if you have many files or folders or want their links?
In those cases, we can use a script to get the list of files and folders in google drive trash bin.
Open Google Apps Script editor and create a new project.
Replace the default function (which already exists) with the below function and run it. Visit creating and executing a Google Apps Script post for more info.
function getListOfFilesAndFoldersInGoogleDriveTrashBin() {
try {
//Trashed Files
const trashedFiles = DriveApp.getTrashedFiles();
while (trashedFiles.hasNext()) {
const file = trashedFiles.next();
const fileName = file.getName();
const fileLink = file.getUrl();
console.log(`File Name: ${fileName} , Link: ${fileLink}`);
}
//Trashed Folders
const trashedFolders = DriveApp.getTrashedFolders();
while (trashedFolders.hasNext()) {
const folder = trashedFolders.next();
const folderName = folder.getName();
const folderLink = folder.getUrl();
console.log(`Folder Name: ${folderName} , Link: ${folderLink}`);
}
} catch (err) {
Logger.log(err)
}
}
By executing the above function, we get the trash bin files and folders with their links in the execution log window.