Does anyone know why this happens? It would be much more convenient to have all the files copied to the destination. I have a list of filenames and file ids 3 are spreadsheets and one is a standalone script which I deploy as a webapp. The three spreadsheet go to the correct place. The standalone webapp goes to the root. I don't think it's a duplicate as suggested.
function backUpProjectFiles(){
var backupFolder=DriveApp.getFolderById(getGlobal('BackupDirId'));
var subFldrName='BackUpFiles_' + Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd_HH:mm:ss');
var subFldr=backupFolder.createFolder(subFldrName);
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('BackUpFiles');
var rg=sh.getDataRange();
var vA=rg.getValues();//column1 is filenames column2 is file ids
var s='<br />Files Backed Up:<br />';
for(var i=1;i<vA.length;i++){
var file=DriveApp.getFileById(vA[i][1]);
file.makeCopy(vA[i][0],subFldr);
s+=Utilities.formatString('%s FilePath:%s/%s/<strong>%s</strong><br />',i,backupFolder.getName(),subFldr.getName(),file.getName());
}
s+=Utilities.formatString('Total Files Copied: %s<br /><input type="button" value="Exit" onClick="google.script.host.close();" />',vA.length-1)
var ui=HtmlService.createHtmlOutput(s).setWidth(600).setHeight(500);
SpreadsheetApp.getUi().showModelessDialog(ui,'File Backup Complete');
}