Apps Script lets you move files between Drive folders using file.moveTo(destination). This is ideal for archiving closed deals, reorganizing reports by region, or automatically routing uploaded files into the right folder.
This example reads each closed deal from the Sales Tracker sheet, finds the matching export file by customer name, and moves it into the correct regional folder:
functionrouteReportsByRegion(){var sheet =SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sales Tracker");var data = sheet.getRange(2,1, sheet.getLastRow()-1,6).getValues();// Columns: [Customer Name, Email, Product, Amount, Region, Sales Rep]var rootFolder =DriveApp.getFolderById("YOUR_ROOT_FOLDER_ID"); data.forEach(function(row){var customerName = row[0];var region = row[4];// Find the report file for this customervar files =DriveApp.searchFiles('title contains "'+ customerName +'" and trashed = false');if(!files.hasNext())return;var file = files.next();// Get or create the destination region foldervar regionFolders = rootFolder.getFoldersByName(region +" - Sales Reports");if(!regionFolders.hasNext())return;var destination = regionFolders.next(); file.moveTo(destination);Logger.log("Moved "+ file.getName()+" to "+ region);});}
For the sample data, Sarah Johnson's report moves to North - Sales Reports, Mark Chen's to East - Sales Reports, and so on.
Copying Instead of Moving
If you want to keep the original in place and put a copy in a new location: