Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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}}
like image 337
Sagar Avatar asked Sep 19 '25 14:09

Sagar


1 Answers

It seems that you are receiving the path from a query string. Once it is clearly encoded you will have to do path = decodeURIComponent(path).

like image 193
Renato Gama Avatar answered Sep 22 '25 03:09

Renato Gama