本文介紹了谷歌應用腳??本 - 迭代文件夾和子文件夾的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想使用 google apps 腳本遍歷 Google Drive 中文件夾的樹結構.下面的代碼列出了一些文件夾,但不是全部.你能建議什么是深入文件夾結構的最佳技術嗎?我首先嘗試記錄所有文件夾名稱.
I want to iterate through the tree structure of the folder in Google Drive using google apps script. The code below is listing some of the folders but not all. Can you advice what is best technique for drill down the folders structure? I am trying to log all folder names at first.
謝謝.
function test() {
listSubfolders(DriveApp.getFolderById('FOLDER_ID'));
}
function listSubfolders(parentFolder) {
var childFolders = parentFolder.getFolders();
while(childFolders.hasNext()) {
Logger.log(childFolders.next().getName());
listSubfolders(childFolders.next());
}
}
推薦答案
要訪問子文件夾,可以這樣,
To access the sub folders, you can do in this way,
function getSubFolders(parent) {
parent = parent.getId();
var childFolder = DriveApp.getFolderById(parent).getFolders();
while(childFolder.hasNext()) {
var child = childFolder.next();
Logger.log(child.getName());
getSubFolders(child);
}
return;
}
function listFolders() {
var parentFolder = DriveApp.getFolderById("0B1n6YLYwFmK_dUpzRWhDRXNwdWc");
var childFolders = parentFolder.getFolders();
while(childFolders.hasNext()) {
var child = childFolders.next();
Logger.log(child.getName());
getSubFolders(child);
}
}
這篇關于谷歌應用腳??本 - 迭代文件夾和子文件夾的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!