元の関数
recursive.gs
// rootFolder: Folderクラス
// type: both, onlyFolder, onlyFile
// func: function(object: Folder or File, type: "Folder" or "File")
function recursive(rootFolder, type, func) {
const files = rootFolder.getFiles()
const folders = rootFolder.getFolders()
if(type=="both" || type=="onlyFile"){
while(files.hasNext()){
func(files.next(), "File")
}
}
while(folders.hasNext()){
const folder = folders.next()
if(type=="both" || type=="onlyFolder") { func(folder, "Folder") }
recursive(folder, type, func)
}
}
使い方
listAllFileAndFolder
function listAllFileAndFolderInFolder(folder){
recursive(folder, "both", function(folderOrFile, type){
console.log(type) // Folder or File
console.log(folderOrFile.getName())
console.log(folderOrFile.getUrl())
})
}