node.js and ncp module - fails to copy single file -


i using node.js v6.3.1 , ncp v2.0.0

i can ncp copy contents of directory, not single file within directory.

here code copying contents of directory recursively works:

var ncp = require("ncp").ncp; ncp("source/directory/", "destination/directory/", callback); 

...and here same code file source:

var ncp = require("ncp").ncp; ncp("source/directory/file.txt", "destination/directory/", callback); 

from can think ncp designed copy directories recursively, not single files maybe?

i had thought using filesystem's read/write stream functions described here consistency hoping stick ncp.

update:

i have found package called node-fs-extra want without need me add event handlers operations, have filesystem read/write solution.

here code working:

var fsextra = require("fs-extra"); fsextra.copy("source/directory/file.txt", "destination/directory/file.txt", callback); 

obviously still inconsistent, @ least little less verbose.

ok have figured out doing wrong.

i trying copy file directory, needed copy , name file inside directory.

so here original code not work:

var ncp = require("ncp"); ncp("source/directory/file.txt", "destination/directory/", callback); 

...and here fixed code working, notice inclusion of file name in destination directory:

var ncp = require("ncp"); ncp("source/directory/file.txt", "destination/directory/file.txt", callback); 

so looks ncp wont take file is, needs specify file name @ other end copy. guess assuming copy file same name destination directory.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -