Nodejs 循环遍历文件夹,修改访问时间和修改时间
作者:互联网
var fs = require("fs");
const {join} = require("path");
function findFilesPath(startPath) {
let result = [];
function finder(path) {
let pathArray = fs.readdirSync(path);
pathArray.forEach((val, index) => {
let fPath = join(path, val);
let stats = fs.statSync(fPath);
if (stats.isDirectory()) finder(fPath);
if (stats.isFile()) {
fs.utimes(fPath, new Date(), (new Date('2021-09-14 17:04')), function (err) {
if (err) {
console.log("修改时间失败")
throw err;
}
})
result.push(fPath);
}
});
}
finder(startPath);
console.log(result);
return false;
}
findFilesPath('F:/my-project/myNode/demo');
最后推广一波服务器
【腾讯云】爆款1核2G云服务器首年48元,还有iPad Pro、Bose耳机、京东卡等你来抽!
标签:遍历,err,Nodejs,fPath,修改,fs,let,result,path 来源: https://blog.csdn.net/qjhsmd2015/article/details/121355091