从DocsList迁移到DriveApp? [英] Migrating from DocsList to DriveApp?
问题描述
我一直在使用DocsList开展一个大型项目,并且工作完美。最近,错误一直在弹出,它们大多数都是根据获取文件夹或文件。当我进行调查时,我发现DriveApp已经更新。问题是DriveApp没有像DocsList这样的搜索参数。例如,如果我有这样的文件夹结构:
根目录
- 主文件夹1
- 文件夹1
- 文件夹2
- 主文件夹2
- 文件夹1
- 文件夹2
在主文件夹2中,我可以输入搜索参数,例如:DocsList.getFolder('Main Folder 2 / Folder 1')
只是无法理解如何使用它。据我所知,我必须为DriveApp做这样的事情: var mainFolders = DriveApp.getFoldersByName('Main Folder 2 );
while(mainFolders.hasNext()){
var mainFolder = termFolders.next();
var subFolders = termFolder.getFoldersByName('Folder 1');
//类似于...
}
所以如果我有一个更深的文件夹,我将不得不进一步扩大这个......?
我觉得不是让事情变得简单,而是让它变得更加复杂FileIterators和FolderIterators。只是让代码中的文件或文件夹变得很难。
因此,基本上,这个主题的目的是要找出一个用户到DocsList导航和编辑Drive文件/文件夹可以迁移到DriveApp并实现相同的目标。
不同场景的小/离散示例将非常有用。我可以从那里拿走它。如果你们认为我不清楚我需要什么帮助,我会进一步编辑。
讨论wchiquito的评论是一个有趣的阅读,但以下所有链接是耗时的。
底线:不会有DriveApp版本的getFolderByPath(),所以你将需要自己推出。在 Google+小组中,Faustino提出了解决方法,Eric对其进行了改进。在这里,增加一个检查来允许以/开头的路径。
函数getFolderByPath(path){
var parts = path.split(/);
if(parts [0] =='')parts.shift(); //路径是否以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;
}
}
返回文件夹;
}
使用它,您可以简单地执行 myFolder = getFolderByPath ('主文件夹2 /文件夹1');
。您将得到一个DriveApp文件夹实例。
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
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')
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..?
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.
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.
The discussions from wchiquito's comment are an interesting read, but following all the links is time-consuming.
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;
}
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屋!