1.3.0 • Published 5 years ago

copy-dir v1.3.0

Weekly downloads
32,852
License
MIT
Repository
github
Last release
5 years ago

copy-dir

Easy used 'copy-dir' lib, even use a filter, copy a file or directory to another path, when target path or parent target path not exists, it will create the directory automatically.

install

npm install copy-dir

grammar

Sync Mode:

copydir.sync(from, to[, options]);

Async Mode:

copydir(from, to, [options, ]callback);

utimes: false, // Boolean | Object, keep addTime or modifyTime if true mode: false, // Boolean | Number, keep file mode if true cover: true, // Boolean, cover if file exists filter: true, // Boolean | Function, file filter

filter is a function that you want to filter the path, then return true or false.

It can use three arguments named state, filepath, filename

* state: String, 'file' / 'directory' / 'symbolicLink', marked as the file or path type
* filepath: String, the file path
* filename: String, the file name

# usage

Sync Mode:

```js
var copydir = require('copy-dir');

copydir.sync('/my/from/path', '/my/target/path', {
  utimes: true,  // keep add time and modify time
  mode: true,    // keep file mode
  cover: true    // cover file when exists, default is true
});

Async Mode:

var copydir = require('copy-dir');

copydir('/my/from/path', '/my/target/path', {
  utimes: true,  // keep add time and modify time
  mode: true,    // keep file mode
  cover: true    // cover file when exists, default is true
}, function(err){
  if(err) throw err;
  console.log('done');
});

add a filter

When you want to copy a directory, but some file or sub directory is not you want, you can do like this:

Sync Mode:

var path = require('path');
var copydir = require('copy-dir');

copydir.sync('/my/from/path', '/my/target/path', {
  filter: function(stat, filepath, filename){
    // do not want copy .html files
    if(stat === 'file' && path.extname(filepath) === '.html') {
      return false;
    }
    // do not want copy .svn directories
    if (stat === 'directory' && filename === '.svn') {
      return false;
    }
    // do not want copy symbolicLink directories
    if (stat === 'symbolicLink') {
      return false;
    }
    return true;  // remind to return a true value when file check passed.
  }
});
console.log('done');

Async Mode:

var path = require('path');
var copydir = require('copy-dir');

copydir('/a/b/c', '/a/b/e', {
  filter: function(stat, filepath, filename) {
    //...
    return true;
  }
}, function(err) {
  //...
});

Update Logs

1.3.0

Bug fix: filter function arguments incorrect, delete the third argument: dirname

Questions?

If you have any questions, please feel free to ask through New Issue.

License

copy-dir is available under the terms of the MIT License.

caweb-cliemulate-bwanil-create-testrollup-plugin-shockytestcafe-allure-reporter-videoredux-saga-crud-generatorredux-saga-generatorredux-saga-crud-cligulpstart-wordpressgenerator-huya-appts-redux-store-templateelizabeth-sdk@naetverkjs/naetverk-cli@tkil/tmpl-clicreate-next-app-lite@ritwikvd/react-templateathena-components-reactyarik-testquizium@nurimansyah/react-starternyks-testcreate-rboilbootstrap-nojs@dotedu/ivx-clirsm-npm-test-packagewindows-service-for-verdaccioapi-makecv-app-payment-adyenrun-npm-packagelabourerssr-enginedensity-ssgmosaic-to-mdswdmarkdowntest-react-scripts-cond@jadefortune/jadefortune-cli@everything-registry/sub-chunk-1380minghuang-clikddatav-climononpmtaro-test-packagetclitao-test-clitax-adminsvn-in-gitteaching-assistantwodlewe-packweb-minifierwd-serverwdngvue-hclivue-cli-plugin-alan-pluginwepy-plugin-usingcomponentswqq-uiwp-sitewpnvwxk-cliwiki-genwhipowx-to-ttxhc-clisuny-resourcetechsumtemplate-genaratortemplate-html-basestarwish-clistblocktestcafe-reporter-alluretestcafe-reporter-allure-customtestcafe-reporter-allure-expandedtestcafe-reporter-allure-vthtestcafe-reporter-easykad4jira-allure-reportertestcafe-reporter-html-logger-customtestcafe-reporter-log-html-reportertestcafe-reporter-acd-html-reportertestforuitestfsutakkuswgj-clithread2ti_recoverux-clivalence-connect-createvidescriptvie-clivida-cli@discuzq.icu/cli@discuzq/cli@discuzqfe/cli@discuzqsdk/cli@crazymad/crazymad-cli@cz.lukasradek/event-dir-prep@cafeta/cli@byteluck-fe/create-control@pbrocks/pbenv@pbrocks/pmaenv@peter.fe/cli@rbotten/sanity-export-diffjd-tiny
1.3.0

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.4.0

7 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago