【发布时间】:2019-05-18 23:11:35
【问题描述】:
我用谷歌搜索过
EPERM:不允许操作
我收到了很多关于 npm 问题和这个错误的点击。
这不是我的情况(不是重复的),因为我没有运行 npm,我正在运行我自己的 Node 代码。
我收到此错误:
错误
{
Error: 'EPERM: operation not permitted',
errno: -1,
code: 'EPERM',
syscall: 'scandir',
path: '../../../Library/Application Support/CallHistoryDB/'
};
在我的主目录上运行以下代码时。
我同时使用了它
节点获取信息
和
sudo 节点获取信息
但我得到同样的错误。
如果我在本地存储库上运行此代码,它可以正常工作,但是当我尝试遍历我的整个主目录时,我得到了错误。
执行代码:
// Libraries
const fs = require('fs');
const h = require('./helper');
// Start recursing here
const start = '../../../';
// API
getThings(start).then(() => {
console.log(data);
}).catch(h.error)
// Accesses the file system and returns an array of files / folders
async function getThings (folder) {
const things = await fs.promises.readdir(folder);
for(let i = 0; i < things.length; i++) {
await getStats(things[i], folder);
}
}
// Gets statistics for each file/folder
async function getStats (thing, folder) {
const path = folder + thing;
const stats = await fs.promises.stat(path);
await checkForFolder(stats, thing, path);
}
// if the file/folder is a folder, recurse and do it again
async function checkForFolder(stats, thing, path){
// logThing(stats, thing, path);
if (stats.isDirectory() ) {
await getThings(path + '/');
}
}
研究
【问题讨论】:
-
您是否尝试重建它是一个一般性错误。真正的错误不是这个
标签: javascript node.js macos recursion runtime-error