Copy Files
Path:
/src/method/copy.coffeecompiled to/lib/method/copy.js
This will copy a single file, complete directory or selection from directory. It will make exact copies of the files as far as possible including times, ownership and access modes. But if some of this rights are not possible to set it will be ignored without an explicit error.
To select which files to copy and how to work you can use the following options:
filter-Array<Object>|ObjectFilter Rulesoverwrite-Booleanif set totrueit will not fail if destination file already exists and overwrite itignore-Booleanit will not fail if destination file already exists but skip this and go on with the next filenoempty-Booleanset totrue to don't create empty directories while no files to copy intodereference-Booleandereference symbolic links and go into themìgnoreErrors-Booleango on and ignore IO errorsparallel-Integernumber of maximum parallel calls in asynchronous run (defaults to half of open files limit per process on the system)
Example:
CoffeeScript Code fs = require 'alinex-fs'
fs.copy '/tmp/some/directory', '/new/destination', (err) ->
return console.error err if err
console.log "Directory copied!"
Or to copy all js files and overwrite existing:
CoffeeScript Code fs = require 'alinex-fs'
fs.copy '/tmp/some/directory', '/new/destination',
filter:
include: '*.js'
overwrite: true
, (err) ->
return console.error err.message if err
console.log "Directory copied!"
copy()
Usage:
copy(source, target, options, cb)
- Parameter
-
source-Stringpath or file to be copiedtarget-Stringfile or directory to copy tooptions-Objectoptional specifications for check defining which files to copycb-function(Error, Array<String>)optional callback with list of newly created files and directly created directories or possibleÈrror:- Target file already exists: xxxxx
copySync()
Usage:
copySync(source, target, options)
- Parameter
-
source-Stringpath or file to be copiedtarget-Stringfile or directory to copy tooptions-Objectoptional specifications for check defining which files to copy
- Return
Array<String>list of newly created files and directly created directories- Throws
-
Errorif anything out of order happened- Target file already exists: xxxxxxxxxxxxxxxxx
Debugging
This module uses thedebug module so you may anytime call your app with
the environment setting DEBUG=fs:copy for the output of this method only.
Because there are mkdirs subcalls here you see the output of DEBUG=fs:* while
copying a small directory:
fs:copy check test/temp/dir3 +32ms
fs:copy going deeper into test/temp/dir3 directory +1ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/dir4? +0ms
fs:copy check test/temp/dir3/file11 +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/dir4 created +0ms
fs:mkdirs directory /home/alex/github/node-fs/test/temp/dir4? +0ms
fs:mkdirs -> directory /home/alex/github/node-fs/test/temp/dir4 was already there +0ms
fs:copy copying file test/temp/dir3/file11 to test/temp/dir4/file11 +0ms