BUY FULL SOURCE CODE
To delete Google Drive files in a specific folder using Google Apps Script, you can follow these steps:
Step 1: Create a new Google Apps Script project
Go to the Google Apps Script Editor by visiting script.google.com and create a new project.
Step 2: Write the code to delete files
Replace the existing code in the editor with the following code:
1 2 3 4 5 6 7 8 9 10 11 |
function deleteFilesInFolder() { var folderId = "YOUR_FOLDER_ID"; // Replace with the ID of the folder containing the files to be deleted var folder = DriveApp.getFolderById(folderId); var files = folder.getFiles(); while (files.hasNext()) { var file = files.next(); DriveApp.getFileById(file.getId()).setTrashed(true); } } |
In the code above, replace YOUR_FOLDER_ID
with the actual ID of the folder that contains the files you want to delete. The deleteFilesInFolder
function retrieves the folder using DriveApp.getFolderById
and gets a list of all the files in the folder using folder.getFiles()
. It then loops through each file and sets the trashed
property to true
using setTrashed(true)
, effectively moving the file to the trash.
Step 3: Save and run the script
Save the script and click on the play button to run it. You may be prompted to authorize the script’s permissions. Grant the necessary permissions for the script to access your Google Drive.
Step 4: Verify the files are deleted
After running the script, it will delete all the files in the specified folder. You can verify by checking the trash in your Google Drive or by visiting the folder to confirm that the files are no longer present.
Note: Deleting files permanently from Google Drive using the setTrashed(true)
method is irreversible. Be cautious when using this script and ensure that you have backups of any important files.
BUY FULL SOURCE CODE