判断文件类型是否所选:
if (stats.isFile() && (filedir.endsWith(".c") || filedir.endsWith(".h") || filedir.endsWith(".cpp"))){ } else if (stats.isDirectory()) { } if (path.extname(currentFile) == ".h") { WeCodeEx.reportLog(' Error:not support head file"*.h"check,only "*.c", "*.cpp", "*.cxx" '); return; }
遍历指定目录及其子目录的所有文件:
public static GetFolderAllFiles(filePath: string) { var files = fs.readdirSync(filePath); ReviewbotService.currentCheckFiles = []; files.forEach(function (filename) { var filedir = path.join(filePath, filename); var stats = fs.statSync(filedir); if (stats.isFile() && (filedir.endsWith(".c") || filedir.endsWith(".h") || filedir.endsWith(".cpp"))) { ReviewbotService.currentCheckFiles.push(filedir); } else if (stats.isDirectory()) { ReviewbotService.GetFolderAllFiles(filedir); // 递归,如果是文件夹,就继续遍历该文件夹下面的文件 } }); }
新建数组及数据的清除:
public static currentCheckFiles = new Array(); currentCheckFiles = [];