查找目录下所有的lib文件,并输出到一个txt中。 直接在项目中加入所有的lib即可,每次还要找有没有哪个lib,真烦。 无 #include fstream#include iostream#include string.h#include Windows.husing namespace std;/* * 找到路径下所有的lib文件 */void Input
直接在项目中加入所有的lib即可,每次还要找有没有哪个lib,真烦。 <无>
#include <fstream> #include <iostream> #include <string.h> #include <Windows.h> using namespace std; /* * 找到路径下所有的lib文件 */ void InputFileLibs(char* szFilename) { fstream fOut; #ifdef _DEBUG cout<<szFilename<<endl; #endif // 如果是lib文件 char* pos=strstr(szFilename,".lib"); if(!pos) return; // 打开文件 fOut.open("libs.txt",ios::app); if(fOut.fail()) { cout<<"读取libs文件失败"<<endl; return; } fOut<<szFilename<<endl; fOut.close(); } int main() { fstream fOut; // 保存要输出的文件 HANDLE handle; WIN32_FIND_DATA fileAttr; char szFilePath[1024]; scanf("%s",szFilePath); // 输入路径名 strcat(szFilePath,"\\*"); // 遍历目录下所有文件 cout<<szFilePath<<endl; // 判断路径名合法 { } // 清理文件 fstream out; out.open("libs.txt",ios::out|ios::trunc); out.close(); handle=FindFirstFile(szFilePath,&fileAttr); if(handle==INVALID_HANDLE_VALUE) { cout<<"invalid handle value"<<GetLastError()<<endl; return 0; } else { char* szFilename=fileAttr.cFileName; InputFileLibs(fileAttr.cFileName); while(FindNextFile(handle,&fileAttr)) { InputFileLibs(fileAttr.cFileName); } if(GetLastError()==ERROR_NO_MORE_FILES) { cout<<"work over"<<endl; } else { cout<<"Some error occurs in the program"<<endl; } FindClose(handle); } return 0; }