Google Apps脚本根据文件名将我的驱动器文件移动到Team驱动器文件夹 [英] Google Apps script move My drive Files to Team drive folder based on file name

查看:59
本文介绍了Google Apps脚本根据文件名将我的驱动器文件移动到Team驱动器文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google Apps脚本的新手.我正在尝试为我们的工作场所获取一个脚本,以将文件从"Google我的云端硬盘"上的单个文件夹移动到Team Drive(如果文件名的一部分包含特定短语).但是,脚本仍会将所有文件从我的云端硬盘"源文件夹移动到Team Drive目标文件夹,即使那些文件名中没有"required"短语的文件也是如此.使用的示例文件名:

I am new to Google Apps Script. I'm trying to get for our workplace a script to move files from a single folder on a Google My Drive, over to a Team Drive if part of the filename has a certain phrase. However the script is still moving any and all files from the My Drive source folder to the Team Drive target folder, even those that don't have the "required" phrase in the file name. Example file names used:

ALT ADJ 01_03_2018

ALT ADJ 01_03_2018

ALT CHG 01_03_2018

ALT CHG 01_03_2018

ALT CHG 01_04_2018

ALT CHG 01_04_2018

ALT PMT 01_03_2018

ALT PMT 01_03_2018

APX ADJ 01_03_2018

APX ADJ 01_03_2018

高级Google服务中启用了Drive API v2

Enabled Drive API v2 in Advanced Google Services under Resources

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文件夹中.请注意,这是整个代码的开始.

In the code, I'm trying to get only files that have the first 7 letters of ALT CHG in the file name to be moved/copied to the Team Drive folder. Instead, all of the files end up in the Team Drive Folder. Note this is the entire code start to finish.

推荐答案

更改:

if (key = "ALT CHG") {

if (key == "ALT CHG") {

这应该可以解决此问题,即使用==代替=

This should fix the issue, i.e. use == instead of =

这篇关于Google Apps脚本根据文件名将我的驱动器文件移动到Team驱动器文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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