Last active
January 28, 2020 10:30
-
-
Save ytkhs/1ec29784f2ad4203bdb4e43c1ce13a74 to your computer and use it in GitHub Desktop.
Google Driveのファイルを再帰的に探す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resultFiles = []; | |
// 再帰的にファイルを探す | |
function getAllFiles(folder, path) { | |
// まずこの階層のファイル | |
var files = folder.getFiles(); | |
while(files.hasNext()){ | |
var file = files.next(); | |
resultFiles.push({'path': path + '/' + file.getName(), 'file': file}); | |
} | |
// この階層のフォルダ | |
var subFolders = folder.getFolders(); | |
var currentPath = path; | |
while (subFolders.hasNext()) { | |
var subFolder = subFolders.next(); | |
path += '/' + subFolder.getName(); | |
// 自身を呼んで再帰処理 | |
resultFiles.concat(getAllFiles(subFolder, path)); | |
path = currentPath; // 現在パスをリセット | |
} | |
return resultFiles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment