问题
Code:
fs.readdir('./commands/', (err, files) => {
// Do something... });
Error:
ENOENT: no such file or directory, scandir './commands/'
The folder ./commands/ does exist. This file is src/index.js and is trying to read the directory of src/commands/. It wouldn't be fs.readdir('/commands' because that would be referring to the root directory of my PC (Ubuntu 18.04 LTS, Node version v8.10.0). If any futher information is required, ask and I will provide.
Thank you all in advance.
回答1:
try with __dirname:
fs.readdir(__dirname +'/commands/', (err, files) => {
// Do something...
})
来源:https://stackoverflow.com/questions/50966704/nodejs-fs-module-returning-no-such-file-or-dir-error