谷歌应用程序脚本。将文件复制到一个驱动器按文件名分隔文件夹 [英] google apps script. copy files to one drive separate folders by file names

查看:3
本文介绍了谷歌应用程序脚本。将文件复制到一个驱动器按文件名分隔文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件从Google驱动器上传到一个驱动器,根据文件名的一部分分开文件夹。例如,这些文件将是:John Doe_story1;John Doe_Story2;Jane Doe_story1;Jane Doe_Story2;等等。因此,这些文件应该上载到不同的文件夹,如";/samplefolder/John Doe/Stories/";;&;/sampleFolder/Jane Doe/Stories/";等。目前,我有一个Google应用程序脚本,可以将文件上传到";/sample文件夹&。脚本由@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.
 }
}

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

推荐答案

如果文件名的格式是像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库中,当文件夹名称不存在时,创建文件夹并将文件上传到创建的文件夹。如果文件夹名称已存在,则文件将上载到现有文件夹。

这篇关于谷歌应用程序脚本。将文件复制到一个驱动器按文件名分隔文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆