判斷文件類型是否所選:
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 = [];