deno.com
在当前页面

文件系统事件

概念 Jump to heading

  • 使用 Deno.watchFs 来监听文件系统事件。
  • 结果可能因操作系统而异。

示例 Jump to heading

要轮询当前目录中的文件系统事件:

watcher.ts
const watcher = Deno.watchFs(".");
for await (const event of watcher) {
  console.log(">>>> event", event);
  // 示例事件: { kind: "create", paths: [ "/home/alice/deno/foo.txt" ] }
}

运行命令:

deno run --allow-read watcher.ts

现在尝试在 watcher.ts 所在的目录中添加、删除和修改文件。

请注意,事件的确切顺序可能因操作系统而异。此功能根据平台使用不同的系统调用:

你找到需要的内容了吗?

隐私政策