📄 findfile.cpp
字号:
#include "StdAfx.h"
#include ".\findfile.h"
CFindFile::CFindFile(void)
{
}
CFindFile::~CFindFile(void)
{
}
#define MAC_FILENAMELENOPATH 256
int CFindFile::FindDirInDir( CString &rootDir, CStringList &lsDirList)
{
char fname[MAC_FILENAMELENOPATH];
ZeroMemory(fname, MAC_FILENAMELENOPATH);
WIN32_FIND_DATA fd;
ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
HANDLE hSearch;
char filePathName[256];
//char tmpPath[256];
CString tmpPath;
ZeroMemory(filePathName, 256);
//ZeroMemory(tmpPath, 256);
strcpy(filePathName, rootDir); //rootDir);
BOOL bSearchFinished = FALSE;
if( filePathName[strlen(filePathName) -1] != '\\' )
{
strcat(filePathName, "\\");
}
strcat(filePathName, "*");
hSearch = FindFirstFile(filePathName, &fd);
//Is directory
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
//strcpy(tmpPath, rootDir);
tmpPath = rootDir;
//strcat(tmpPath, fd.cFileName);
tmpPath.Append( fd.cFileName);
tmpPath.Append( "\\");
lsDirList.AddTail( tmpPath);
FindDirInDir(tmpPath, lsDirList);
}
while( !bSearchFinished )
{
if( FindNextFile(hSearch, &fd) )
{
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
//strcpy(tmpPath, rootDir);
tmpPath = rootDir;
//strcat(tmpPath, fd.cFileName);
tmpPath.Append( fd.cFileName);
tmpPath.Append( "\\");
lsDirList.AddTail( tmpPath);
FindDirInDir(tmpPath, lsDirList);
}
}
else
{
if( GetLastError() == ERROR_NO_MORE_FILES ) //Normal Finished
{
bSearchFinished = TRUE;
}
else
bSearchFinished = TRUE; //Terminate Search
}
}
FindClose(hSearch);
return TRUE;
}
int CFindFile::FindFileInDir(CString &rootDir, CStringList &lsFileList, CString &strFliter) //char* rootDir, char* strRet)
{
char fname[MAC_FILENAMELENOPATH];
ZeroMemory(fname, MAC_FILENAMELENOPATH);
WIN32_FIND_DATA fd;
ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
HANDLE hSearch;
char filePathName[256];
//char tmpPath[256];
CString tmpPath;
ZeroMemory(filePathName, 256);
//ZeroMemory(tmpPath, 256);
strcpy(filePathName, rootDir); //rootDir);
BOOL bSearchFinished = FALSE;
if( filePathName[strlen(filePathName) -1] != '\\' )
{
strcat(filePathName, "\\");
}
strcat(filePathName, strFliter); //"*.cpp");
hSearch = FindFirstFile(filePathName, &fd);
////Is directory
//if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// && strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
//{
// //strcpy(tmpPath, rootDir);
// tmpPath = rootDir;
// //strcat(tmpPath, fd.cFileName);
// tmpPath.Append( fd.cFileName);
// tmpPath.Append( "\\");
// FindFileInDir(tmpPath, lsFileList);
//}
//else
if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") && strlen(fd.cFileName) > 0)
{
//sprintf(fname, "%-50.50s", fd.cFileName);
//strcat(strRet + strRet[strlen(strRet)] , fname);
CString name = rootDir;
name.Append( fd.cFileName);
lsFileList.AddTail( name);
}
while( !bSearchFinished )
{
if( FindNextFile(hSearch, &fd) )
{
//if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// && strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
//{
// //strcpy(tmpPath, rootDir);
// tmpPath = rootDir;
////strcat(tmpPath, fd.cFileName);
// tmpPath.Append( fd.cFileName);
// tmpPath.Append( "\\");
//FindFileInDir(tmpPath, lsFileList);
//}
//else
if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
CString name = rootDir;
name.Append( fd.cFileName);
lsFileList.AddTail( name);
}
}
else
{
if( GetLastError() == ERROR_NO_MORE_FILES ) //Normal Finished
{
bSearchFinished = TRUE;
}
else
bSearchFinished = TRUE; //Terminate Search
}
}
FindClose(hSearch);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -