ts筆記

判斷文件類型是否所選:

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 = [];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章