使用searchFiles或getFilesByName不会产生任何结果 [英] Using searchFiles or getFilesByName isn't yielding any results

查看:77
本文介绍了使用searchFiles或getFilesByName不会产生任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,该脚本会将Google云端硬盘中的大量照片和视频分类到文件夹中,以使妻子更容易找到所需的内容.不幸的是,她必须使用云端硬盘而不是Google Photos,因此她无法使用Photos可以为她提供的更强大的排序功能.

I'm trying to write a script that will sort large numbers of photos and videos on Google Drive into folders that make it easier for my wife to find what she's looking for. Unfortunately, she has to use Drive rather than Google Photos, so she doesn't have access to the much more robust sorting functionality that Photos would give her.

警告:我不是程序员,所以我真的不知道自己在做什么.我认为我要告诉脚本要查找的文件夹,然后告诉它搜索在文件名方面符合某些条件的文件,但是脚本从其搜索结果中返回null

Warning: I'm not a programmer, so I really don't know what I'm doing. I think I'm telling the script what folder to look in and then telling it to search for files that meet certain criteria in terms of name of the file, but the script is returning null from its search results.

我曾尝试使用searchFiles(以名称包含[my string var]作为参数")和getFilesByName(以我的字符串var作为参数).在这两种情况下,我都得到了命名文件夹,但没有文件.

I have tried using both searchFiles (with "name contains [my string var]" as the param), and getFilesByName (with my string var as the param). In both cases, I'm getting named folders but no files.


      var currDate = strMonth + strDay;
      var photos = currFolder.getFilesByName(
        "" + "2019" + currDate + "");

      var activeFolder = currFolder.createFolder(currDate);
      if (photos.hasNext()) {
        myLog = Logger.log("HasNext");

      } else {
        myLog = Logger.log("Doesn't HasNext");
      }
      while ( photos.hasNext() ) {
        var currPhoto = photos.next();
        currPhoto.makeCopy(activeFolder);
        myLog = Logger.log(currPhoto);
      }

我希望照片是脚本已找到的照片列表,然后可以将其复制到我创建的文件夹中.我的调试日志记录总是告诉我hasNext()是FALSE,这似乎与没有文件复制到文件夹的事实是一致的.

What I expect is that photos is a list of pictures the script has found, that can then be copied over to the folder I created. My debug logging always tells me hasNext() is FALSE, though, and this seems to agree with the fact that no files are getting copied into the folder.

任何帮助将不胜感激.我确定我只是在做一些愚蠢的事情.谢谢!

Any help would be greatly appreciated. I'm sure I'm just doing something dumb. Thanks!

推荐答案

以下是显示所有JPEG文件的示例

function findJPEGFiles() {
  var files=DriveApp.getFilesByType(MimeType.JPEG);
  var html='<style>td,th{border:1px solid black;}</style><table><tr><th>Name</th><th>Id</th><th>Url</th></tr>';
  while(files.hasNext()) {
    var file=files.next();
    html+=Utilities.formatString('<tr><td>%s</td><td>%s</td><td>%s</td></tr>',file.getName(),file.getId(),file.getUrl());
  }
  html+='</table>';
  var userInterface=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Files');
}

这篇关于使用searchFiles或getFilesByName不会产生任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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