我正在尝试找出递归扫描目录并获得信息之王的最佳方法:
[
{ name: '/path1/file1',
size: 123,
checksum : 534534,
mtime: 'yyyy-mm-dd HH:m:s'
},
{ name: '/path1/file2',
size: 123132,
checksum : 555,
mtime: 'yyyy-mm-dd HH:m:s'
},
{ name: '/path2/file3',
size: 122,
checksum : 515155,
mtime: 'yyyy-mm-dd HH:m:s'
}
]
我找到了fs-jetpack模块,该模块可以将此类信息返回给我:
{
"name":"APP",
"type":"dir",
"size":1101381678,
"children":[
{
"name":".DS_Store",
"type":"file",
"size":6148,
"md5":"7b0eee6703916548d1df569dd1172e40"
},
{
"name":"R1542708834",
"type":"dir",
"size":1089804745,
"children":[
{
"name":"img",
"type":"dir",
"size":1089804745,
"children":[
{
"name":"1542710799.jpg",
"type":"file",
"size":374099,
"md5":"ea4a9932d24c4a79e808a2b8d55f3328"
},
{
"name":"1542711457.jpg",
"type":"file",
"size":26373,
"md5":"d9e7f6d6b8ea18b1cb452d9e9f20d79e"
}
]}
]
},
{
"name":"css",
"type":"dir",
"size":884493,
"children":[
{
"name":"fo.css",
"type":"file",
"size":201178,
"md5":"b7704c0ed2ee09a8fa371be97cc6ebf4"
},
{
"name":"fo2.css",
"type":"file",
"size":187696,
"md5":"897eeb42ac7ba1c83e105af9c5117467"
}]
}
]
}
mtime丢失了,输出的格式也不是我期望的。 最好的方法是什么?我不想多次扫描目录以获取所有必需的信息(mtime,校验和,大小,路径和文件名)。
我的代码很简单:
const jetpack = require('fs-jetpack');
const dirpath = path.join('/var/www');
var ret = jetpack.inspectTree(dirpath, {checksum: 'md5', relativePath: false});
我也尝试过dirtyree模块,但是我总是会错过一些信息。