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