文件系统 (fs) 找不到其中包含 space 的文件(节点 js)

File System (fs) cannot find a file with space in it (Node js)

我开发了一个文件系统,我从一个文件夹开始,当用户点击它们时递归地显示文件夹和文件。

我在文件名之间没有白色 space 的地方遍历没有问题,但是一旦我输入带有白色 space 的名称,我就会收到错误消息。示例:

Home
 .My Documents
 .Downloads
 .Desktop

我收到的 fs 错误是

REQUEST ./Home/My%20Documents
{ Error: ENOENT: no such file or directory, scandir './Home/My%20Documents'
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: './Home/My%20Documents' }

我试图查找它,但任何人都可以提示我如何解决这个问题吗?

content.hbs

{{#each contents}}
            <tr>
                {{#if isFolder}}
                <td>
                    <a href="/{{name}}">
                    <div><img style="vertical-align:middle" src="folder.png" height="32" width="32" > <span style="margin-left: 20px">{{name}}</span></div></a> </td>
                <td></td>
                <td></td>
                {{else}}
                <td><div><img style="vertical-align:middle" src="file.png" height="32" width="32" > <span style="margin-left: 20px">{{name}}</span></div> </td>
                <td>{{size}} Mb</td>
                <td></td>
                {{/if}}
            </tr>
            {{/each}}

您似乎正在从查询字符串中接收路径。明确编码后,您将必须执行 path = decodeURIComponent(path).