I'm having some trouble on Windows with the copy function. Others on our team are using Linux and seem to have no trouble. The following snippet gives me an error unless I create the 'target/folderA/' directory beforehand.
var fsextra = require('fs-extra');
fsextra.copy('source/folderA/folderB', 'target/folderA/folderB', function (err) {
if (err) {
console.error(err);
} else {
console.log('good');
}
});
The error I get is:
[ { [Error: ENOENT: no such file or directory, mkdir 'c:\dx\fs-extra-test\target\folderA\folderB']
errno: -4058,
code: 'ENOENT',
syscall: 'mkdir',
path: 'c:\\dx\\fs-extra-test\\target\\folderA\\folderB' } ]
Is this expected behaviour on Windows or a bug?
Regards
Weird. Can you change this to absolute directories using path.resolve() to see if this is still a bug? I'm wondering if there's a bug somewhere related to relative directories.
I think there may be a fundamental difference between mkdir on Windows versus mkdir on Linux. I think Windows needs parent directories to exist first. I vaguely remember something like this from another project in the past, or I dreamt it. It may be more appropriate to use your own mkdirs command or equivalent.
oh wait, using path.resolve() worked, as in:
fsextra.copy(path.resolve('source/folderA/folderB'), path.resolve('target/folderA/folderB'),
@jprichardson ping?
@jprichardson ping?
Seems to me that the paths should be resolved in advance by copy()... thoughts @RyanZim?
If you can run path.resolve on input without side effects, I'd say do it!
If you can run path.resolve on input without side effects,
This is the biggest concern. IDK, can we safely assume this? Maybe not?
@jprichardson I'll leave that to you.
@jprichardson I'll leave that to you.
Since I can't say for certainty, I think we should pass on path.resolve for the time being. If someone else reads this is knows otherwise, please comment.
@jprichardson right it just copied when it used like this
fs.copySync(path.resolve(sourceFile), path.resolve(targetFile));
Most helpful comment
Since I can't say for certainty, I think we should pass on
path.resolvefor the time being. If someone else reads this is knows otherwise, please comment.