gpt4 book ai didi

node.js - Nodejs 中的 fs.readFileSync() 错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:21:24 24 4
gpt4 key购买 nike

我正在 nodejs 中使用 require('fs'); 调用同步调用

var folder_path = '/home/abc';
var myfiles = ['a.png','b.png'];
_.each(myfiles, function(name){
var data = fs.readFileSync(folder_path+'/'+name);
if(data){
// Some operation
}
});

在调用该函数时,我收到错误:EISDIR,对目录的非法操作

fs.js:488
var r = binding.read(fd, buffer, offset, length, position);
^
Error: EISDIR, illegal operation on a directory
at Object.fs.readSync (fs.js:488:19)
at Object.fs.readFileSync (fs.js:322:28)
at /home/coader/dev/api/controllers/MyController.js:66:30
at Function.forEach ( /home/coader/dev/node_modules/sails/node_modules/lodash/dist/lodash.js:3298:15)
at /home/coader/dev/api/controllers/MyController.js:41:11
at Object.oncomplete (fs.js:108:15)
error: Forever detected script exited with code: 8

详情

$ node -v
v0.10.37

$ nodejs -v
v0.10.37

$ npm -v
1.4.28

任何答案都将受到重视。

谢谢

最佳答案

我认为你可能不得不满足于“myfiles.forEach(function(name)”

var folder_path = '/home/abc';
var myfiles = ['a.png','b.png'];
myfiles.forEach(function(name){
var data = fs.readFileSync(folder_path+'/'+name);
if(data){
// Some operation
}
});

关于node.js - Nodejs 中的 fs.readFileSync() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33199612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com