删除文件.

如果文件不存在或者是目录，则不做修改
349312
public static void deleteFile(@Nullable Path path) throws IOException {
		Validate.isTrue(isFileExists(path), "%s is not exist or not a file", path);

		Files.delete(path);
	}
408301
async function scanFile (dir, ext, ret_absolute)
{
return new Promise( async function(resolve, reject){
    // console.log(dir);
    fs.readdir(dir, function(err, files){
        let file_arr = [];
        if( ! files ){
            return resolve(file_arr);
        }
        files.forEach(function(elm){
            if( elm.indexOf('.') > -1 ){
                if( !ext || '.'+ext.toUpperCase()==path.extname(elm).toUpperCase() ){
                    // 返回全路径
                    if( ret_absolute ){
                        elm = path.join(dir, elm);
                    }
                    // 检查文件后缀名
                    file_arr.push(elm);
                }
            }
        });
        resolve(file_arr);
    });
});
}
660907
function getContentOfDir(pathToDir) {
  return fs.readdirSync(pathToDir).filter(function(fileName) {
    return !hiddenReg.test(fileName);
  });
}
1271127
function getdirFiles(dir, prefix = '') {
  dir = path.normalize(dir);
  if (!fs.existsSync(dir)) return [];
  const files = fs.readdirSync(dir);
  let result = [];
  files.forEach(item => {
    const currentDir = path.join(dir, item);
    const stat = fs.statSync(currentDir);
    if (stat.isFile()) {
      result.push(path.join(prefix, item));
    } else if (stat.isDirectory()) {
      const cFiles = getdirFiles(currentDir, path.join(prefix, item));
      result = result.concat(cFiles);
    }
  });
  return result;
}
1340201
function(file, options) {
		file = this.absPath(file);
		var cwd = (options && options.cwd) || '';
		if (file.substring(0, cwd.length) == cwd) {
			file = file.substring(cwd.length);
			if (file.charAt(0) != '/') {
				file = '/' + file;
			}
		}

		return file;
	}
717234
function getDirectories(path){
  return fs.readdirSync(path).filter(function (file) {
    return fs.statSync(path + "/" + file).isDirectory();
  });	
}
852456
function readDir(dir) {
    var files = [];
    var root = fs.readdirSync(dir);
    var readMe = false;
    for (var i = 0; i < root.length; i++) {
        var filePath = dir + '/' + root[i];
        var stat = fs.statSync(filePath);
        //console.log(filePath,dir);
        filePath = path.relative(dir, filePath);
        if (stat && stat.isDirectory()) {
            files.push({
                dir: true,
                path: filePath
            });
        } else {
            files.push({
                dir: false,
                path: filePath
            });
        }

        // check if it is readme
        if(root[i].toLowerCase() === 'readme.md'){
            readMe = dir + '/' + root[i];
        }
    }
    return {
        files: files,
        readMe : readMe
    };
}
466101
function copyFile(src, dist, callback) {
    let rs = fs.createReadStream(src),
        ws = fs.createWriteStream(dist);

    // 监听事件
    rs.on('error', callback);
    ws.on('error', callback);
    ws.on('close', callback);

    // 传输文件
    rs.pipe(ws);
}
343321
function _emptyDirectoryProm (directory) {

			return new Promise((resolve, reject) => {

				readdir(directory, (err, files) => {
					return err ? reject(err) : resolve(files);
				});

			}).then((files) => {

				const result = [];

					for (let i = 0; i < files.length; ++i) {
						result.push(join(directory, files[i]));
					}

				return Promise.resolve(result);

			}).then((files) => {
				return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
			});

		}
313850
function replaceStringsInFile(name, rootDir, replacements) {
  return findFirstFile(name, rootDir)
  .then(function (path) {
    return fs.readFileAsync(path, 'utf8')
    .then(function (content) {
      return replaceContent(path, content, replacements);
    })
    .then(function (content) {
      return fs.writeFileAsync(path, content, 'utf8');
    });

  })
  .catch(function (error) {
    console.error(
      'we couldn\'t replace strings in file, error: \'%s\', stack: \'%s\'',
      error.toString(), error.stack
    );
    return Promise.reject(error);
  });
}
170205
function executeFile(src, { context, babelOptions } = {}) {
    let filename = resolvePath(context)(src);

    // 不存在文件
    if (!filename) {
        throw new Error(`Error: ENOENT: no such file, open '${src}'`);
    }

    // 解析【json】
    if (filename.endsWith('.json')) {
        return require(filename);
    }

    // 解析对象
    return execute(
        fs.readFileSync(filename, 'utf-8'), { filename, babelOptions }
    );
}
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();
    });
}
1095197
function readdir(path) {
	var stats = fs.lstatSync(path);
	var files = null;
	if (stats.isDirectory()) {
		fileNames = fs.readdirSync(path);
		files = _.map(fileNames, function(f) { return path + '/' + f; });
	} else {
		files = [];
	}
	return files;
}
798765
function getlist(fpath, prefix) {
    try {
      folders = fs.readdirSync(fpath);
    } catch (e) {
      return;
    }

    prefix = prefix || '';

    _.each(folders, function(f) {
      var p;
      npath = path.join(fpath, f);

      // 如果当前f是文件夹，则添加代表文件夹的分隔符，否则判断文件名是否匹配正则，不匹配则不扔进数组
      if (fs.existsSync(npath) && fs.lstatSync(npath).isDirectory()) {

        f += '/';

        // 如果要获取所有文件则递归获取下一层目录的文件
        if (hasGrep) getlist(npath, prefix + f);

      } else if (f.match(re)) {

        p = re ? RegExp.$1 : f;

      } else {
        return;
      }

      // 如果grepKey为string则匹配文件/文件夹名
      if (hasGrep && f.indexOf(grepKey) === -1) return;

      urlList.push({
        name: f,
        path: prefix + (p || f)
      });
    });
  }
998532
async function mapdir(src, callback) {
    let stats = await stat(src),
        result = [];

    // 判断是否存在文件夹
    if (stats) {
        let fullpath = path.cwd(src),
            data = assign(stats, { path: fullpath });


        // 执行回调
        result.push(callback ? callback(data) : data);

        // 处理文件夹
        if (stats.isDirectory() && !fullpath.endsWith('node_modules')) {
            let files = await readdir(src);

            // 遍历下级文件
            for (let file of files) {
                result = result.concat(await mapdir(path.join(src, file), callback));
            }
        }
    }

    // 返回结果
    return result;
}
1253476
async function find(...args) {

    // 查找文件
    for (let name of args) {
        let dir = path.cwd(name),
            stats = await stat(dir);

        // 查找成功
        if (stats) {
            return Object.create(stats, { path: { get() { return dir; } } });
        }
    }

    // 返回空
    return null;
}
1074728
function () {
        var fileList = [];
        /*获取原文件列表*/
        Object.keys(src).forEach(function(key){
            fileList.push(src[key]);
        });
        return fileList;
    }