JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 86113
  • Score
    100M100P100Q216311F
  • License MIT

copy-dir

Package Exports

  • copy-dir

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (copy-dir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

copy-dir

easy used 'copy-dir', copy a file or directory to anothor path, when distpath or parent distpath not exist, it will create the directory automatically.

install

npm install copy-dir

grammar

Sync:

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

Async:

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

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

It can use three arguments named stat, filepath, filename

  • stat: 'file' or 'directory', mark the file or path a file or directory
  • filepath: the file path
  • filename: the file name

usage

Sync:

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

copydir.sync('/a/b/c', '/a/b/e');

Async:

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

copydir('/a/b/c', '/a/b/e', function(err){
  if(err){
    console.log(err);
  } else {
    console.log('ok');
  }
});

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:

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

copydir.sync('/a/b/c', '/a/b/e', function(stat, filepath, filename){
  var status = true;
  if (stat === 'file' && path.extname(filepath) === '.html') {
    // copy files, but without .html
    status = false;
  } else if (stat === 'directory' && filename === '.svn') {
    // copy directories, but without .svn
    status = false;
  }
  return status;
}, function(err){
  console.log('ok')
});

Async:

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

copyDir('/a/b/c', '/a/b/e', function(stat, filepath, filename){
  //...
});