从 DocsList 迁移到 DriveApp? [英] Migrating from DocsList to DriveApp?

查看:15
本文介绍了从 DocsList 迁移到 DriveApp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为一个大项目使用 DocsList,它运行良好.最近,错误不断涌现,它们大多源于获取文件夹或文件.当我做研究时,我发现 DriveApp 已经更新了.问题是 DriveApp 没有像 DocsList 那样的搜索参数.

I've been using DocsList for a big project and it was working perfectly. Lately, bugs have been popping up and they mostly have roots with getting a folder or file. When I did research, I found that DriveApp had been updated. The problem is that DriveApp doesn't have search parameters like DocsList had.

例如,如果我有这样的文件夹结构:

For example, if I had a folder structure like this:

Root
-Main Folder 1
--Folder 1
--Folder 2
-Main Folder 2
--Folder 1
--Folder 2

要在主文件夹 2"中获取文件夹文件夹 1",我可以像这样输入搜索参数:DocsList.getFolder('Main Folder 2/Folder 1')

To get folder "Folder 1" in "Main Folder 2," I could put in the search parameter like so: DocsList.getFolder('Main Folder 2/Folder 1')

使用 DriveApp,我只是不明白如何使用它.据我了解,我必须为 DriveApp 做这样的事情:

With DriveApp, I just can't understand how to work with it. From what I understand, I have to do something like this for DriveApp:

var mainFolders = DriveApp.getFoldersByName('Main Folder 2');
while (mainFolders.hasNext()) {
  var mainFolder = termFolders.next();
  var subFolders = termFolder.getFoldersByName('Folder 1');
  // Something like this...
}

因此,如果我有一个更深"的文件夹,我将不得不进一步扩展它..?

So if I had a folder that is more "deep" I would have to expand this even further..?

我觉得他们不是让事情变得更容易,而是让所有的 FileIterators 和 FolderIterators 变得更加复杂.而且只是很难用代码术语获取"文件或文件夹.

I feel like instead of making things easier, they made it more complicated with all the FileIterators and FolderIterators. And just making it hard to "get" a file or folder in code terms.

因此,基本上,此线程的目的是找出使用 DocsList 导航和编辑 Drive 文件/文件夹的人如何迁移到 DriveApp 并实现相同的目标.

So basically, the point of this thread is to find out how a person who is use to DocsList to navigate and edit Drive files/folders can migrate to DriveApp and achieve the same things.

不同场景的小/离散示例将非常有帮助.我可以从那里拿走它.如果你们认为我不清楚我需要帮助的内容,我会进行更多编辑.

Small/Discrete examples of different scenarios would be really helpful. I can take it from there. I'll edit this more, if you guys think I'm not being clear about what I need help on.

推荐答案

wchiquito 评论中的讨论很有趣,但是跟踪所有链接很耗时.

The discussions from wchiquito's comment are an interesting read, but following all the links is time-consuming.

底线:不会有 DriveApp 版本的 getFolderByPath(),因此您需要自己推出.在 Google+ 群组中,Faustino 提出了一种解决方法,Eric 对其进行了改进.就是这样,添加了一个检查以允许以/"开头的路径.

Bottom line: There will not be DriveApp version of getFolderByPath(), so you will need to roll your own. In the Google+ group, Faustino proposed a work-around and Eric improved it. Here it is, with an added check to allow paths that start with "/".

function getFolderByPath(path) {
  var parts = path.split("/");

  if (parts[0] == '') parts.shift(); // Did path start at root, '/'?

  var folder = DriveApp.getRootFolder();
  for (var i = 0; i < parts.length; i++) {
    var result = folder.getFoldersByName(parts[i]);
    if (result.hasNext()) {
      folder = result.next();
    } else {
      return null;
    }
  }
  return folder;
}

有了它,您可以简单地执行 myFolder = getFolderByPath('Main Folder 2/Folder 1');.您最终会得到一个 DriveApp 文件夹实例.

With that, you can simply do myFolder = getFolderByPath('Main Folder 2/Folder 1');. You will end up with a DriveApp Folder instance.

这篇关于从 DocsList 迁移到 DriveApp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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