4.18. copy-dir

简介:

install

		
npm install copy-dir		
		
		

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) {
  //... 
});
		





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
mkdir: cannot create directory `**': No such file or directory
在mkdir时报错的解决方案,在网上找了很多文章都没有说清楚原因。
430 0
|
5月前
|
存储 Python
copy
【6月更文挑战第10天】
32 0
|
6月前
|
Shell
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
109 0
|
6月前
|
C#
C# File.Copy介绍
C# File.Copy介绍
|
6月前
|
算法 C++ 容器
【C++11算法】find_if_not、 copy_if、copy_n
【C++11算法】find_if_not、 copy_if、copy_n
123 0
ftok info: No such file or directory
ftok info: No such file or directory
201 0
|
Linux Windows
SVN更新被Locked,Can't open file 'folder/.svn/tmp/text-base/file.svn-base'
SVN更新被Locked,Can't open file 'folder/.svn/tmp/text-base/file.svn-base'
174 0
SVN更新被Locked,Can't open file 'folder/.svn/tmp/text-base/file.svn-base'