【问题标题】:google apps script. copy files to one drive separate folders by file names谷歌应用脚​​本。按文件名将文件复制到一个驱动器单独的文件夹
【发布时间】:2022-02-15 16:34:10
【问题描述】:

我想根据部分文件名将文件从谷歌驱动器上传到一个驱动器单独的文件夹。例如文件是:John Doe_story1; John Doe_story2; Jane Doe_story1; Jane Doe_story2;等等。所以这些文件应该上传到单独的文件夹,例如“/samplefolder/John Doe/Stories/”; “/samplefolder/Jane Doe/Stories/”;等等。目前我有一个谷歌应用脚​​本将文件上传到“/samplefolder”。脚本是在@Tanaike 的帮助下编写的,如下:

function myFunction() {
var prop = PropertiesService.getScriptProperties();
var odapp = OnedriveApp.init(prop);
var source = DriveApp.getFolderById("###"); // Please put your folder ID.
var files = source.getFiles();
while (files.hasNext()) {
var file = files.next();
odapp.uploadFile(file.getId(), "/samplefolder/"); // Please set the destination folder name. In this case, the folder name in OneDrive.
 }
}

如果有人能帮我完成剧本,我将不胜感激。提前感谢您的帮助。

【问题讨论】:

    标签: google-apps-script google-drive-api onedrive


    【解决方案1】:

    如果文件名的格式是For instance the files would be: John Doe_story1; John Doe_story2; Jane Doe_story1; Jane Doe_story2; and ect.这样的常量,那么下面的修改呢?

    发件人:

    odapp.uploadFile(file.getId(), "/samplefolder/");
    

    收件人:

    odapp.uploadFile(file.getId(), `/samplefolder/${file.getName().split("_")[0]}/Stories/`);
    
    • OnedriveApp的库中,当文件夹名称不存在时,创建文件夹并将文件上传到创建的文件夹中。当文件夹名称存在时,文件将上传到现有文件夹。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      • 2021-12-31
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多