diff --git a/src/xmlsql.cpp b/src/xmlsql.cpp index 5775c49..afe4bef 100644 --- a/src/xmlsql.cpp +++ b/src/xmlsql.cpp @@ -8,8 +8,11 @@ #include #include #include -// #include -#include +#ifdef _WIN32 + #include +#else + #include +#endif #include #include #include @@ -250,36 +253,37 @@ void produceXML(const char *xml, const char *connectorFile, string resultfile) branchTree.init(); } +#ifdef _WIN32 // VSMC io.h 支持下使用 -// void getAllFiles(string path, vector &files) -// { -// // 文件句柄 -// long long hFile = 0; -// // 文件信息 -// struct _finddata_t fileinfo; -// string p; -// if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) -// { -// do -// { -// if ((fileinfo.attrib & _A_SUBDIR)) -// { // 比较文件类型是否是文件夹 -// if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) -// { -// files.push_back(p.assign(path).append("\\").append(fileinfo.name)); -// // 递归搜索 -// getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files); -// } -// } -// else -// { -// files.push_back(p.assign(path).append("\\").append(fileinfo.name)); -// } -// } while (_findnext(hFile, &fileinfo) == 0); // 寻找下一个,成功返回0,否则-1 -// _findclose(hFile); -// } -// } - +void getAllFiles(string path, vector &files) +{ + // 文件句柄 + long long hFile = 0; + // 文件信息 + struct _finddata_t fileinfo; + string p; + if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) + { + do + { + if ((fileinfo.attrib & _A_SUBDIR)) + { // 比较文件类型是否是文件夹 + if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) + { + files.push_back(p.assign(path).append("\\").append(fileinfo.name)); + // 递归搜索 + getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files); + } + } + else + { + files.push_back(p.assign(path).append("\\").append(fileinfo.name)); + } + } while (_findnext(hFile, &fileinfo) == 0); // 寻找下一个,成功返回0,否则-1 + _findclose(hFile); + } +} +#else void getAllFiles(string path, vector &files) { @@ -294,10 +298,11 @@ void getAllFiles(string path, vector &files) continue; files.push_back(std::__fs::filesystem::path(path).append(dirp->d_name)); } - closedir(dp); } +#endif + // 初始化各个结构体