admin管理员组文章数量:1336568
I have developed a file system where I start with one folder and I display folders and files recursively as the user clicks on them.
I have no issue traversing where there is no white space between file names, but as soon as I enter a name with white space, I receive an error. Example:
Home
.My Documents
.Downloads
.Desktop
the Error I receive by the fs is
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' }
I tried to look it up, but can anyone give me a hint about how to get through this?
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}}
I have developed a file system where I start with one folder and I display folders and files recursively as the user clicks on them.
I have no issue traversing where there is no white space between file names, but as soon as I enter a name with white space, I receive an error. Example:
Home
.My Documents
.Downloads
.Desktop
the Error I receive by the fs is
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' }
I tried to look it up, but can anyone give me a hint about how to get through this?
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}}
Share
edited Mar 20, 2018 at 23:45
Sagar
asked Mar 20, 2018 at 23:08
SagarSagar
4167 silver badges26 bronze badges
1 Answer
Reset to default 7It seems that you are receiving the path from a query string. Once it is clearly encoded you will have to do path = decodeURIComponent(path)
.
本文标签: javascriptFile System (fs) cannot find a file with space in it (Node js)Stack Overflow
版权声明:本文标题:javascript - File System (fs) cannot find a file with space in it (Node js) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742402825a2468228.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论