使用this rmdir库我在测试之前成功清理了我的目录,以便测试我的文件下载并避免已经存在的文件发生错误传递。
exec('rm -r ' + path, function (err, stdout, stderr) {
if (err) {
console.log('------------------------------------------------------------------------');
console.log(' ERROR!!! -- Folder download was not cleaned up before test or it is wrong WARN');
console.error(err)
console.log('------------------------------------------------------------------------');
}
但问题是我有回调函数并且它捕获了这个错误:
ERROR!!! -- Folder download was not cleaned up before test or it is wrong WARN
{ Error: Command failed: rm -r /Users/myPath/Downloads
rm: /Users/alexandertunick/Downloads: Permission denied
它没什么可怕但是当真正发生错误时它可能会引起误报。