7.12 文件系统事件

2021-08-10  本文已影响0人  9e8aeff1c70c

概念

例子

要轮询当前目录中的文件系统事件,请执行以下操作:

/**
 * 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相同的目录中添加、删除和修改文件。

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

上一篇 下一篇

猜你喜欢

热点阅读