Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copy-dir

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-dir

copy-dir

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
80K
decreased by-7.41%
Maintainers
1
Weekly downloads
 
Created
Source

copy-dir

Easy used 'copy-dir' method, even use a filter, copy a file or directory to anothor path, when target path or parent target path not exists, 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 state, filepath, filename

  • state: '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('/my/from/path', '/my/target/path');

Async:

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

copydir('/my/from/path', '/my/target/path', 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('/my/from/path', '/my/target/path', function(stat, filepath, filename){
  if(stat === 'file' && path.extname(filepath) === '.html') {
    return false;
  }
  if (stat === 'directory' && filename === '.svn') {
    return false;
  }
  return true;
}, 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){
  //...
}, function(err) {
  //...
});

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.

Keywords

FAQs

Package last updated on 14 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc