【问题标题】:I am using fs module readdir but I keep getting this error (Error: ENOENT: no such file or directory, scandir)我正在使用 fs 模块 readdir 但我不断收到此错误(错误:ENOENT:没有这样的文件或目录,scandir)
【发布时间】:2021-06-02 15:58:43
【问题描述】:

我在我的 react 文件夹结构中创建了一个包含视频的视频文件夹,我想访问这个文件夹中的文件,我遇到了 fs 模块,但是无论我尝试了多少不同的解决方案,它都显示该文件没有即使它在那里也存在。

fs.readdir('./src/videos', (err, files) => {
      if (err)
        console.log(err);
      else {
        console.log(files);
        files.forEach(file => {
          console.log(file);
        })
      }
    })

【问题讨论】:

    标签: javascript fs


    【解决方案1】:

    您的代码没有问题,请确保路径正确。 检查文件夹与运行代码的位置相关的位置。 检查文件夹的名称 - 确保没有拼写错误。

    【讨论】:

    • 是的,我刚刚意识到我输入了错误的路径。谢谢
    猜你喜欢
    • 2017-12-28
    • 2021-04-27
    • 2021-12-05
    • 2021-12-04
    • 1970-01-01
    • 2022-09-30
    • 2019-10-14
    • 1970-01-01
    • 2017-10-07
    相关资源
    最近更新 更多