Reputation: 87
I have a script that pulls the ID of a file within a specific folder, then takes a copy and puts that into another folder then deletes it from the original folder.
However when the takes a copy it then copies any attached google forms and places them in the folder also.
Is there a way to only copy the sheet?
var sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Copies")
var folder = DriveApp.getFolderById('FOLDER_ID'); //Latest Copy ID
var list = [];
list.push(['Name','ID','Size']);
var files = folder.getFiles();
while (files.hasNext()){
file = files.next();
var row = []
row.push(file.getName(),file.getId(),file.getSize())
list.push(row);
}
sh.getRange(1,1,list.length,list[0].length).setValues(list);
var value = SpreadsheetApp.getActiveSheet().getRange(2, 2).getValue();
var archive = DriveApp.getFolderById("ARCHIVE_ID"); // Backup Folder
var file = DriveApp.getFileById(value);
var name = file.getName();
// makes copy of "file" with "name" at the "destination"
file.makeCopy(name, archive);
file.setTrashed(true); // sets the file in the trash of the user's Drive
}
Upvotes: 0
Views: 42
Reputation: 2774
All files in your folder are found and processed, you're not checking for a specific file type.
Check the file type before you write to the array.
if (file.getMimeType() === 'application/vnd.google-apps.spreadsheet') {
var row = [];
row.push(file.getName(),file.getId(),file.getSize());
list.push(row);
}
Upvotes: 1