Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Last active January 28, 2020 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytkhs/1ec29784f2ad4203bdb4e43c1ce13a74 to your computer and use it in GitHub Desktop.
Save ytkhs/1ec29784f2ad4203bdb4e43c1ce13a74 to your computer and use it in GitHub Desktop.
Google Driveのファイルを再帰的に探す
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