
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
获取文件夹内所有的文件。支持递归获取、异步或同步、过滤、返回信息处理。
npm install dirfile
var dirfile = require('dirfile');
var path = require('path');
//扫描文件夹路径
var dirPath = 'd:/folder/',
//是否异步获取
async = true,
//是否递归查询子级目录
isDeep = true;
//# 同步获取文件
dirfile(dirPath,async,isDeep,function(filePath,stat){
return path.extname(filePath) == '.java';
},function(filePath,stat){
return {
name : path.basename(filePath),
filePath : filePath
}
})
.then(function(fileList){
console.log(fileList);//打印文件列表信息
})
.catch(function(err){
console.log(err);
})
//使用同步获取
async = false;
var fileList2 = dirfile(dirPath,async,isDeep,function(filePath,stat){
return path.extname(filePath) == '.java';
},function(filePath,stat){
return filePath;
})
console.log(fileList2);//打印输出即可
//简单调用
dirfile(dirPath)
.then(function(fileList){
console.log(fileList);
})
promise 函数,通过 then 调用。如果为false ,则直接同步获取,直接返回获得文件列表。(默认为true)true)filePath stat . 文件路径以及文件状态信息,需要返回true/false.{filePath : filePath} 。 可自定义返回值,提供参数filePath stat .参数为向前补充的,第一个参数为dirPath 保持不变,如果有两个则第二个参数为 infoFn ,如果有三个则pushFn infoFn ,类似这样。
简单做了一个测试,异步要比同步快一倍左右,当然都是小文件,大文件可能差别更多。没有进行细致的测试。
MIT
FAQs
The npm package dirfile receives a total of 26 weekly downloads. As such, dirfile popularity was classified as not popular.
We found that dirfile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.