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

📄 search.cpp

📁 打印数据生成和模拟
💻 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 + -