/* Copyright (c) 2020 RafaƂ Rajtar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include using namespace std; namespace fs = std::filesystem; template void println(Args... args) { (std::cout << ... << args) << "\n"; } int sum_of_lines = 0; fs::path root_path; int printFileData(fs::path path) { ifstream file; file.open(path); int lines = 0; string line; while (getline(file, line)) lines++; auto fn = path.filename(); println(fn, std::string(30 - fn.string().length(), ' '), lines); return lines; } int printAllWithExtension(const char* ext) { println("Listing Files With ", ext, " Extension"); int sum_of_lines = 0; for (auto f : fs::recursive_directory_iterator(root_path)) { auto path = f.path(); if (path.extension().string() == ext) { sum_of_lines += printFileData(path); } } println("Lines Of Code With This Extension: ", sum_of_lines, "\n"); return sum_of_lines; } template void printAllWithExtensions(T ext) { sum_of_lines += printAllWithExtension(ext); println("Total Lines Of Code: ", sum_of_lines, "\n\n\n"); } template void printAllWithExtensions(T ext, U... exts) { sum_of_lines += printAllWithExtension(ext); printAllWithExtensions(exts...); } int main() { println("PROGRAM START"); root_path = "C:\\Users\\haski\\source\\repos\\KBU\\KBU"; printAllWithExtensions(".cpp", ".h", ".glsl"); println("PROGRAM END"); system("pause"); }