FilesApp
FilesApp is a GAS library for retrieving file and folder list in Google Drive using Google Apps Script (GAS). Also this can create a tree from all files and folders in Google Drive.
AI Summary
FilesApp
GAS library to retrieve file/folder lists from Google Drive and create trees.
Target Users
Beginner to advanced GAS developers building apps needing hierarchical file/folder lists from Google Drive.
Problems Solved
Requires creating scripts each time to retrieve hierarchical file and folder lists from Google Drive.
Script ID
- In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
- "FilesApp" will appear in the search results
- Select the latest version (highest number) from "Version" dropdown
- Click "Add"
Tags
Main Features
1
Tree Creation
Retrieves all files/folders under a folder as level-aware tree including shared drives.
2
Flat Retrieval
Gets all files/folders flatly without tree structure, faster than createTree.
3
Flexible Methods
Provides 4 methods: tree, flat all, folders only, direct children with custom fields/mimeType.
Examples
Main Functions
| Function | Description |
|---|---|
| FilesApp.createTree(folderId, mimeType, fields, accessToken) | Creates hierarchical tree. |
| FilesApp.getAllInFolder(folderId, mimeType, fields, accessToken) | Retrieves all files/folders flatly. |
| FilesApp.getFilesAndFoldersInFolder(folderId, mimeType, fields, accessToken) | Gets direct files/folders. |
Examples
Create Folder Tree
/**
* フォルダ階層ツリー作成
* ・全階層再帰取得: FilesApp.createTree(folderId, null, "files(name)")
* ・ツリー構造確認: res.folderTreeById, res.folderTreeByName
* ・統計値取得: res.totalFilesAndFolders, res.totalFiles, res.totalFolders
*/
function createTreeSample(folderId) {
var res = FilesApp.createTree(folderId, null, "files(name)");
console.log(res);
}Get All Files/Folders Flat
/**
* 全ファイル・フォルダフラット取得
* ・高速フラット一覧: FilesApp.getAllInFolder(folderId, null, "files(name)")
* ・ツリーなし配列: res は全ファイル・フォルダのフラット配列
* ・全階層カバー: 指定フォルダ以下の全レベルを1配列にまとめる
*/
function getAllInFolderSample(folderId) {
var res = FilesApp.getAllInFolder(folderId, null, "files(name)");
console.log(res);
}