I need some help, I have the script below that converts a ".xls" file into google spreadsheet, but I need you to always use the most recent file that is in folder A, I can't do that.
function importXLS(){
var folderBId = "ID FOLDER"; // Added // Please set the folder ID of "FolderB".
var files = DriveApp.getFolderById('ID FOLDER').searchFiles('title != "nothing"');
while(files.hasNext()){
var xFile = files.next();
var name = xFile.getName();
if (name.indexOf('.xls')>-1){
var ID = xFile.getId();
var xBlob = xFile.getBlob();
var newFile = {
title : 'backlog' '_converted',
parents: [{id: folderBId}] // Added
};
file = Drive.Files.insert(newFile, xBlob, {
convert: true
});
}
}
}
CodePudding user response:
Most recently updated file in a folder
function mostrecentlyupdatedfileinafolder() {
const folder = DriveApp.getFolderById(gobj.globals.testfolderid);
const files = folder.getFiles();
const fa = [];
while(files.hasNext()) {
let file = files.next();
fa.push(file);
}
fa.sort((a,b) => {
return b.getLastUpdated().valueOf() - a.getLastUpdated().valueOf();
});
//let fnA = fa.map(f => f.getName()).flat();
//Logger.log(JSON.stringify(fnA));
return fa[0];
}