#include #include #include #include #include #include namespace fs = std::filesystem; class AdvancedNfoFileChecker { private: std::vector videoExtensions = {".avi", ".m2ts", ".mkv", ".mp4", ".ts"}; std::map checkResults; public: bool isVideoFile(const fs::path &filePath) { std::string extension = filePath.extension().string(); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); return std::find(videoExtensions.begin(), videoExtensions.end(), extension) != videoExtensions.end(); } bool hasNfoFile(const fs::path &videoPath) { fs::path nfoPath = videoPath; nfoPath.replace_extension(".nfo"); return fs::exists(nfoPath); } void checkFolderRecursive(const std::string &folderPath, bool recursive = false) { checkResults.clear(); int totalVideoFiles = 0; int missingNfoCount = 0; try { auto iterator = fs::directory_iterator(folderPath); for (const auto &entry : iterator) { if (entry.is_regular_file()) { fs::path filePath = entry.path(); if (isVideoFile(filePath)) { totalVideoFiles++; bool hasNfo = hasNfoFile(filePath); checkResults[filePath.string()] = hasNfo; if (!hasNfo) { missingNfoCount++; } } } } printResults(totalVideoFiles, missingNfoCount); } catch (const fs::filesystem_error &ex) { std::cerr << "错误:无法访问文件夹 '" << folderPath << "'" << std::endl; std::cerr << "详细信息: " << ex.what() << std::endl; } } private: void printResults(int totalVideoFiles, int missingNfoCount) { std::cout << "检查结果:" << std::endl; std::cout << "==========================================" << std::endl; std::cout << "总视频文件数: " << totalVideoFiles << std::endl; std::cout << "缺少.nfo的文件数: " << missingNfoCount << std::endl; std::cout << "完整率: " << (totalVideoFiles - missingNfoCount) * 100 / std::max(1, totalVideoFiles) << "%" << std::endl; std::cout << "==========================================" << std::endl; if (missingNfoCount > 0) { std::cout << "缺少.nfo文件的视频文件:" << std::endl; for (const auto &[filepath, hasNfo] : checkResults) { if (!hasNfo) { std::cout << " ✗ " << fs::path(filepath).filename().string() << std::endl; } } } else if (totalVideoFiles > 0) { std::cout << "✓ 所有视频文件都有对应的.nfo文件" << std::endl; } else { std::cout << "! 在指定文件夹中未找到视频文件" << std::endl; } } }; int main(int argc, char *argv[]) { AdvancedNfoFileChecker checker; std::string folderPath; bool recursive = false; // 解析命令行参数 for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; if (arg == "-r" || arg == "--recursive") { recursive = true; } else if (arg == "-h" || arg == "--help") { std::cout << "用法: " << argv[0] << " [文件夹路径] [-r]" << std::endl; std::cout << "选项:" << std::endl; std::cout << " -r, --recursive 递归检查子文件夹" << std::endl; std::cout << " -h, --help 显示帮助信息" << std::endl; return 0; } else { folderPath = arg; } } if (folderPath.empty()) { std::cout << "请输入要检查的文件夹路径(留空使用当前目录): "; std::getline(std::cin, folderPath); if (folderPath.empty()) { folderPath = "."; } } std::cout << "正在检查文件夹: " << fs::absolute(folderPath) << std::endl; if (recursive) { std::cout << "模式: 递归检查(包含子文件夹)" << std::endl; } std::cout << "支持的视频格式: .avi, .m2ts, .mkv, .mp4, .ts" << std::endl; std::cout << "==========================================" << std::endl; checker.checkFolderRecursive(folderPath, recursive); return 0; }