Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  167] [ 3]  / answers: 1 / hits: 36165  / 8 Years ago, tue, july 26, 2016, 12:00:00

I'm trying to copy an image from a folder to another using fs-extra module .



var fse = require('fs-extra');

function copyimage() {
fse.copy('mainisp.jpg', './test', function (err) {
if (err)
return console.error(err)
});
}


This is my directory



and this is the error I get all the time:




Error {errno: -4058, code: ENOENT, syscall: lstat, path:
E:mainisp.jpg, message: ENOENT: no such file or directory, lstat
'E:mainisp.jpg'}






and by changing destination to ./test/ I get this error




Error {errno: -4058, code: ENOENT, syscall: lstat, path:
E:DevelopmentNode appsNode softwaresDigital_librarymainisp.jpg,
message: ENOENT: no such file or directory, lstat 'E:Devel…
appsNode softwaresDigital_librarymainisp.jpg'}




Note: I'm not testing this in browser. It's an Nwjs app and the pics of error attached are from Nwjs console.


More From » node.js

 Answers
15

Try:



var fs = require('fs-extra');

fs.copySync(path.resolve(__dirname,'./mainisp.jpg'), './test/mainisp.jpg');


As you can see in the error message, you're trying to read the file from E:mainisp.jpg instead of the current directory.



You also need to specify the target path with the file, not only the destination folder.


[#61247] Saturday, July 23, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yosefleod

Total Points: 113
Total Questions: 100
Total Answers: 115

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;