Reputation: 121
I'm using the module 'fs' to perform some OS integration and one of the procedures I do is to create/write files on the system. I've noticed that when using the function 'writeFile' and the path has spaces the procedure fails.
eg (working):
fs.writeFile('/home/john/mypath/myfile.txt', 'blabla', function() {})
eg (failing):
fs.writeFile('/home/john/my path/myfile.txt', 'blabla', function() {})
The error I'm getting is the following:
{ [Error: ENOENT: no such file or directory'] errno: -2, code: 'ENOENT', syscall: 'open', path: '"/home/john/my path/another cool/project.txt"' }
Any insights on how to workaround this? Thanks!
Upvotes: 0
Views: 3221
Reputation: 106
You need to escape the spaces with a backwards slash. ie ..
fs.writeFile('/home/john/my\ path/myfile.txt', 'blabla', function() {})
Upvotes: 0