我试图找出在上传文件时文件夹中的哪个文件已更改。为此,我尝试使用fs.watch。我用
const watcher = fs.watch(watchDir, (eventname, filename) => {
console.log("Watcher: " + filename);
});
//Code
const getCookie = ClientFunction(() => {
return document.cookie;
});
let xmlresult = await helpers.getXMLInfo('', testCorpusid, caseid);
console.log("Test message");
//Code
watcher.close()
但是看起来// Code部分内部什么都没有执行。我觉得我在这里误会了吧?有人可以提示我如何观看文件夹异步吗?
您必须将所需的代码放在回调函数中的每个文件更改上运行,如下所示:
const watcher = fs.watch(watchDir, async (eventname, filename) => {
console.log("Watcher: " + filename);
const getCookie = ClientFunction(() => {
return document.cookie;
});
let xmlresult = await helpers.getXMLInfo('', testCorpusid, caseid);
console.log("Test message");
});
阅读有关回调here的更多信息。