檔案系統事件
概念 跳至標題
- 使用 Deno.watchFs 來監看檔案系統事件。
- 結果可能因作業系統而異。
範例 跳至標題
要在目前目錄中輪詢檔案系統事件
watcher.ts
const watcher = Deno.watchFs(".");
for await (const event of watcher) {
console.log(">>>> event", event);
// Example event: { kind: "create", paths: [ "/home/alice/deno/foo.txt" ] }
}
執行方式
deno run --allow-read watcher.ts
現在嘗試在與 watcher.ts
相同的目錄中新增、移除和修改檔案。
請注意,事件的確切順序可能會因作業系統而異。此功能根據平台使用不同的系統呼叫
- Linux:inotify
- macOS:FSEvents
- Windows:ReadDirectoryChangesW