有人知道为什么会这样吗?将所有文件复制到目标位置将更加方便。我有一个文件名和文件ID的列表3是电子表格,一个是我作为Web应用程序部署的独立脚本。这三个电子表格会转到正确的位置。独立的webapp进入根目录。我不认为这是重复的建议。
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');
}
答案 0 :(得分:2)
我通过使用Drive API的“更新”方法修改了脚本。复制文件后,此脚本的流程如下。
makeCopy()
复制文件。subFldr
。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]);
var res = file.makeCopy(vA[i][0],subFldr); // Modified
if (file.getMimeType() == MimeType.GOOGLE_APPS_SCRIPT) { // Added
Drive.Files.update({"parents": [{"id": subFldr.getId()}]}, res.getId()); // Added
}
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');
}