文件系统事件
概念 跳转到标题
- 使用 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