【问题标题】:Google Apps script move My drive Files to Team drive folder based on file nameGoogle Apps 脚本根据文件名将我的驱动器文件移动到团队驱动器文件夹
【发布时间】:2019-10-16 13:31:06
【问题描述】:

我是 Google Apps 脚本的新手。我正在尝试为我们的工作场所获取一个脚本,以将文件从 Google 我的云端硬盘上的单个文件夹移动到团队云端硬盘(如果文件名的一部分具有特定短语)。但是,该脚本仍在将所有文件从“我的云端硬盘”源文件夹移动到“团队云端硬盘”目标文件夹,即使是那些文件名中没有“必需”短语的文件。 使用的示例文件名:

ALT ADJ 01_03_2018

ALT CHG 01_03_2018

ALT CHG 01_04_2018

ALT PMT 01_03_2018

APX 调整 01_03_2018

在资源下的高级 Google 服务中启用 Drive API v2

function moveFileToFolder() { 
  var upldFldr=DriveApp.getFolderById('<<original Folder ID>>');
  var files=upldFldr.getFiles();
  supportsTeamDrives: true;
  while(files.hasNext()) {
    var file=files.next();
    var key=file.getName().slice(0,7);  //intended to take the first 7 characters of the filename.
      if (key = "ALT CHG") {
        supportsTeamDrives: true;
        supportTeamDrives: true;
        var targetFolder = DriveApp.getFolderById('<<new folder ID>>');
        targetFolder.addFile(file);
      };
  }
}

在代码中,我试图仅将文件名中包含 ALT CHG 前 7 个字母的文件移动/复制到 Team Drive 文件夹。相反,所有文件最终都在 Team Drive 文件夹中。请注意,这是从头到尾的整个代码。

【问题讨论】:

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


    【解决方案1】:

    变化:

    if (key = "ALT CHG") {
    

    if (key == "ALT CHG") {
    

    这应该可以解决问题,即使用 == 而不是 =

    【讨论】:

    • 谢谢。我有一种感觉,这将是一个简单的修复。现在完美运行。
    猜你喜欢
    • 1970-01-01
    • 2019-12-31
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 2014-08-07
    相关资源
    最近更新 更多