このページのすべてのメソッドは app.files にあります。
const app = await api.applications.fetch("abc123def456abc123def456");
app.files; // FilesModule
ディレクトリ内のファイル一覧取得
app.files.list(path?) はディレクトリのエントリを返します。パスのデフォルトは "/" です。
const entries = await app.files.list("/");
console.log(entries);
// [
// { type: "file", name: "index.js", size: 123, lastModified: 1717084800000 },
// { type: "directory", name: "src", size: 0, lastModified: 1717084800000 },
// ]
ファイルの読み取り
app.files.read(path) はファイルの内容を Node.js の Buffer として返します。ファイルが存在しない場合は undefined を返します。
const buffer = await app.files.read("/index.js");
console.log(buffer?.toString("utf8"));
ファイルの作成または上書き
app.files.create(file, fileName, path?) は path/fileName にファイルを書き込みます。パスのデフォルトは "/" です。
| Parameter | Type | Description |
|---|
file | string | Buffer | ローカルファイルのパス、または生の Buffer の内容 |
fileName | string | 拡張子付きのファイル名(例:"version.ts") |
path | string | アプリ内の絶対ディレクトリパス(デフォルト "/") |
const content = Buffer.from("export default 1\n");
await app.files.create(content, "version.ts", "/src");
import { join } from "node:path";
const localPath = join(__dirname, "version.ts");
await app.files.create(localPath, "version.ts", "/src");
シグネチャは v4 で変更されました。以前のバージョンは create(content, fullPath) を受け付けていましたが、v4 では create(content, fileName, path) が必要です。
ファイルの移動または名前変更
app.files.move(path, newPath) はファイルまたはディレクトリを移動または名前変更します。
await app.files.move("/version.ts", "/src/version.ts");
ファイルまたはディレクトリの削除
app.files.delete(path) はファイルまたはディレクトリ全体を削除します。
await app.files.delete("/src/version.ts");