⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.cpp

📁 一个我自己做的东西
💻 CPP
字号:
// Search.cpp: implementation of the Search class.//////////////////// 
#include "afx.h" 
#include "Search.h" 
#include "direct.h" 
#include <iostream>
Search::Search(CString strFilePath, CString strFileName) 
{ 
getcwd(m_szOldDir, MAX_PATH); // 保存遍历前的起始目录 
if(chdir((LPCTSTR)strFilePath) == -1) // 进入指定目录 
//AfxMessageBox("路径错误");
m_strFileName = strFileName; 
} //--------------------------------------------------------------------- 

void Search::Start() 
{ 
BOOL ans; 
CFileFind find; 
Run(); // 在每一个目录下执行自定义的操作 
ans = find.FindFile("*.*"); 
while(ans) 
{ 
ans = find.FindNextFile(); // 查找下一个文件 
// 查找到的如果是目录并且不是 . 或 .. 
if((find.IsDirectory() == TRUE) && (find.IsDots() != TRUE)) 
{ 
chdir((LPCTSTR)find.GetFilePath()); // 如果是目录则进入继续查找 
Start(); // 递归调用 
chdir(".."); // 返回后回到上一层目录继续查找 
} 
} // End of while 
find.Close(); 
return; 
} //--------------------------------------------------------------------- 

Search::~Search() { chdir(m_szOldDir); // 返回遍历前的起始目录 } 

//--------------------------------------------------------------------- 
void Search::Run() 
{ 
BOOL run_ans; 
CFileFind run_find; // m_strFileName 就是 Search 构造函数的第二个参数 
run_ans = run_find.FindFile(m_strFileName); 
while(run_ans) 
{ 
run_ans = run_find.FindNextFile(); 
if(!run_find.IsDots()) 
{ // TODO: 请在这里添加你的代码 
TRACE("\n%s", run_find.GetFilePath()); 
} 
} 
run_find.Close(); 
return 0; 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -