?? search.cpp
字號:
// Search.cpp: implementation of the Search class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ToolSoftForPrint.h"
#include "Search.h"
#include "direct.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Search::Search(CString strFilePath, CString strFileName)
{
getcwd(m_szOldDir, MAX_PATH); // 保存遍歷前的起始目錄
if(chdir((LPCTSTR)strFilePath) == -1) // 進入指定目錄
AfxMessageBox("路徑錯誤");
m_strFileName = strFileName;
} //---------------------------------------------------------------------
void Search::Start(CStringArray &arr)
{
BOOL ans;
CFileFind find;
Run(arr); // 在每一個目錄下執行自定義的操作
ans = find.FindFile("*.*");
while(ans)
{
ans = find.FindNextFile(); // 查找下一個文件
// 查找到的如果是目錄并且不是 . 或 ..
if((find.IsDirectory() == TRUE) && (find.IsDots() != TRUE))
{
CString s =find.GetFilePath();
chdir((LPCTSTR)find.GetFilePath()); // 如果是目錄則進入繼續查找
Start(arr); // 遞歸調用
chdir(".."); // 返回后回到上一層目錄繼續查找
}
} // End of while
find.Close();
return;
} //---------------------------------------------------------------------
void Search::Start(CString &path)
{
BOOL ans;
CFileFind find;
ans = find.FindFile("*.*");
while(ans)
{
ans = find.FindNextFile(); // 查找下一個文件
// 查找到的如果是目錄并且不是 . 或 ..
if((find.IsDirectory() == TRUE) && (find.IsDots() != TRUE))
{
CString s =find.GetFilePath();
if (s != "")
{
path =s;
return ;
}
chdir((LPCTSTR)find.GetFilePath()); // 如果是目錄則進入繼續查找
Start(path); // 遞歸調用
chdir(".."); // 返回后回到上一層目錄繼續查找
}
} // End of while
find.Close();
return;
} //---------------------------------------------------------------------
Search::~Search()
{ chdir(m_szOldDir); // 返回遍歷前的起始目錄
}
//---------------------------------------------------------------------
void Search::Run(CStringArray &arr)
{
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: 請在這里添加你的代碼
arr.Add(run_find.GetFilePath());
}
}
run_find.Close();
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -