删除文件或目录（含子目录及文件）
513854
function remove(path) {
	let files = [];
	if( fs.existsSync(path) ) {
		if(fs.statSync(path).isFile()){
			fs.unlinkSync(path);
			return;
		}

		files = fs.readdirSync(path);
		files.forEach(function(file, index){
			let curPath = path + "/" + file;
			if(fs.statSync(curPath).isDirectory()) {
				remove(curPath)
			} else {
				fs.unlinkSync(curPath);
			}
		});
		fs.rmdirSync(path, err=>console.error(err));
	}
}
1125687
function copyExamp(path,pathLength){
	fs.readdir(path,function(err, files){
		if(err){
			console.log('examples read dir err:' + path);
		}else{
			// 遍历目录下所有子项
			files.forEach(function(item){
				var tmpPath = path + '/' + item;
				fs.stat(tmpPath,function(err, stat){
					if(stat.isFile()){
						// 判断文件类型,如果是.html则转化
						var htmlIndex = item.indexOf('.html');
						var jsIndex = item.indexOf('.js');
						var cssIndex = item.indexOf('.css');
						if(htmlIndex < 0 && (jsIndex > -1 || cssIndex > -1)){
							// 创建读取流
		                    readable = fs.createReadStream( tmpPath );
		                    // 创建写入流
		                    writable = fs.createWriteStream( 'examples/' + tmpPath.substring(pathLength) );
		                    // 通过管道来传输流
		                    readable.pipe(writable);
						}
						if(htmlIndex > -1){
							fs.readFile(tmpPath,function(err,data){
								var htmlStr = '';
								if(err){
									console.log('read html err:' + tmpPath)
								}else{
									htmlStr = data.toString();
								}
								var ctx = 'http://design.yonyoucloud.com/static/'
								var tpl = [
							        '<!DOCTYPE html>',
							        '<html lang="en">',
							        '<head>',
							        '<meta charset="UTF-8">',
							        '<meta name="viewport" content="width=device-width, initial-scale=1">',
							       	'<title>Title</title>',
									'<link rel="stylesheet" href="'+ ctx +'/font-awesome/css/font-awesome.css">',
							       	'<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/u.css">',
							       	'<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/u-extend.css">',
								    '<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/tree.css">',
							        '<link rel="stylesheet" type="text/css" href="'+ ctx +'/uui/latest/css/grid.css">',
							        '<link rel="stylesheet" type="text/css" href="widget.css">',
							        '</head>',
							        '<body>',
							        htmlStr,
							        '<script src="'+ ctx +'/jquery/jquery-1.11.2.js"></script>',
							    	'<script src="'+ ctx +'/knockout/knockout-3.2.0.debug.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u-polyfill.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u-tree.js"></script>',
							        '<script src="'+ ctx +'/uui/latest/js/u-grid.js"></script>',
									'<script src="'+ ctx +'/requirejs/require.debug.js"></script>',
									'<script src="widget.js"></script>',
							        '</body>',
							        '</html>'
						        ]
					        	var tplStr = tpl.join('\r\n');
					        	fs.writeFile('examples/' + tmpPath.substring(pathLength),tplStr,function(err){
						        	if(err){
						        		console.log('write err:' + 'examples/' + item + '.html');
						        	}
						        })
					        })
						}
					}
					// 子项为目录创建目录
					if(stat.isDirectory()){
						var dirPath = 'examples/' + tmpPath.substring(pathLength);
						fs.exists(dirPath, function(exist) {
							if(!exist){
								fs.mkdirSync(dirPath);
							}
						});
						copyExamp(tmpPath,pathLength);
					}
				})
			})
		}
	})
}
367037
function formatPath(filePath, root) {
  let dir = root;

  if (!path.isAbsolute(root)) {
    dir = path.join(process.cwd(), root);
  }

  // 修复windows下的\路径问题
  dir = dir.replace(/\\/g, '/');

  return filePath
    .replace(/\\/g, '/')
    .replace(dir, '')
    .split('.')[0];
}
757202
function rmdir(src, callback) {
    stat(src).then(async stats => {

        // 判断是否存在文件夹
        if (stats) {
            try {
                if (stats.isDirectory()) {
                    let files = await proxy.readdir(src);

                    // 移除下级目录
                    await Promise.all(
                        files.map(file => proxy.rmdir(path.join(src, file)))
                    );

                    // 移除文件夹
                    await origin.rmdir(src);
                } else {
                    await proxy.unlink(src);
                }
            } catch (err) {
                return callback(err);
            }
        }

        // 执行回调
        callback();
    });
}
509110
def mkdir(self, children, mode=0o0755, return_node=True):
        
        result = None

        if isinstance(children, (str, unicode)):
            if os.path.isabs(children):
                raise BadValueError('Cannot mkdir an absolute path: {path}'.format(path=self._pyerarchy_path))

            rel_path = os.path.join(self._pyerarchy_path, children)
            os.makedirs(rel_path, mode)

            if return_node:
                result = Node(rel_path)
        else:
            for child in children:
                self.mkdir(child, mode, False)

        return result
1189710
def parent_directory(self):
        """"""
        self.chdir(os.path.join(getcwd_or_home(), os.path.pardir))
392323
def walk_dir_with_filter(pth, prefix=None, suffix=None):
    
    if suffix is None or type(suffix) != list:
        suffix = []
    if prefix is None or type(prefix) != list:
        prefix = []

    r = []
    for root_, dirs, files in os.walk(pth):
        for file_ in files:
            full_pth = os.path.join(root_, file_)

            # 排除 \.开头文件, 及 .pyc .md 结尾文件
            c = False
            for x in prefix:
                if file_.startswith(x):
                    c = True
                    break
            if c:
                continue
            # if runs here , c is False
            for x in suffix:
                if file_.endswith(x):
                    c = True
                    break
            if c:
                continue

            r.append(full_pth)
    return r
619546
function walkTree(directory, callback) {
    callback(directory);
    directory.directories.forEach(childDirectory => walkTree(childDirectory, callback));
}
1095772
def rm_files_in_dir(path):
    
    for f in os.listdir(path):
        try:
            os.remove(f)
        except PermissionError:
            os.chmod(f, 0o777)
            try:
                os.remove(f)
            except Exception:
                pass
    return
562095
function mkdirp(path) {
	var dirname = Path.dirname(path);
	if( exists(dirname, "d") ) return true;
	else{
		mkdirp(dirname);
		FS.mkdirSync(dirname, 0700);
	}
}
5349
function (directory, filename) {

        return Path.join(directory, filename).replace(/^[a-z]:\\/i, '/').replace(/\\/g, '/');

    }
1064458
function mkdir(path, fn) {
  shell.mkdir('-p', path);
  shell.chmod(755, path);
  console.log(chalk.cyan('   create:'), path);
  if (fn) fn();
}
495715
def _get_sub_dirs(parent):
    """"""
    return [child for child in os.listdir(parent) if os.path.isdir(os.path.join(parent, child))]
1278068
function joinDirectory() {
  var dirs = [].slice.call(arguments, 1);
  var dir;
  for (var i = 0, len = dirs.length; i < len; i++) {
    dir = dirs[i];
    if (/^\//.test(dir)) {
      // 发现根目录, 直接返回.
      return dir;
    }
  }
  return join.apply(null, [].slice.call(arguments));
}
165502
function mkdir(file, ignorePoint) {
	let dirs = file.split(/[/\\]/);
	if(!ignorePoint && dirs[dirs.length - 1].indexOf('.') >= 0){
		dirs.length = dirs.length -1;
	}

	let path = '';
	for(let i = 0; i < dirs.length; i++){
		if (i==0) {
			path = dirs[i] + '/' ;
		}else{
			path += dirs[i] + '/';
		}

		if (!fs.existsSync(path)) {
			fs.mkdirSync(path, err=>console.error(err))
		}
	}
}
394746
def make_parent_dirs(path, mode=0o777):
  
  parent = os.path.dirname(path)
  if parent:
    make_all_dirs(parent, mode)
  return path
704042
def build_dirs(files):
    '''
    
    '''
    for i in files:
        if type(i) is list:
            build_dirs(i)
            continue
        else:
            if len(i['path']) > 1:
                addpath = os.path.join(os.getcwd(), *i['path'][:-1])
                subdirs = all_subdirs(os.getcwd())
                if addpath and addpath not in subdirs:
                    os.makedirs(addpath)
                    print 'just made path', addpath