惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
NISL@THU
NISL@THU
I
Intezer
Project Zero
Project Zero
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security Affairs
Latest news
Latest news
N
News and Events Feed by Topic
N
News and Events Feed by Topic
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
AWS News Blog
AWS News Blog
SecWiki News
SecWiki News
Attack and Defense Labs
Attack and Defense Labs
O
OpenAI News
The Last Watchdog
The Last Watchdog
月光博客
月光博客
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog
Recorded Future
Recorded Future
G
Google Developers Blog
雷峰网
雷峰网
T
Threat Research - Cisco Blogs
罗磊的独立博客
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园_首页
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
Spread Privacy
Spread Privacy
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
Simon Willison's Weblog
Simon Willison's Weblog
Forbes - Security
Forbes - Security
Webroot Blog
Webroot Blog
The Register - Security
The Register - Security
T
Troy Hunt's Blog
P
Privacy & Cybersecurity Law Blog
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Know Your Adversary
Know Your Adversary
C
Check Point Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
H
Help Net Security
T
Threatpost
L
LangChain Blog
博客园 - 聂微东
T
Tenable Blog
I
InfoQ

博客园 - 吴文力

VC 开机自动启动程序代码 Symbian中音频API的使用(摘录) symbian 游戏开发中一些技术细节(摘录) Symbian中声音处理 动态库的调用等技术 VC小技巧 15个问题 - 吴文力 - 博客园 VC 常见问题百问 VC/MFC Q&A 200409 DELL 电脑的区别 报表式CListCtrl的使用详解初稿 俄罗斯科学家语出惊人:怀孕前就能预设生男生女 PE文件格式详解 如何让程序自动管理线程 WinNT & Win2K下实现进程的完全隐藏——宿主程序 木马病毒是如何利用文件关联和设置名感染的 104种清除木马完全攻略 Programming Applications for Microsoft Windows(四) Programming Applications for Microsoft Windows(三) Programming Applications for Microsoft Windows(二)
怎样在目录中寻找文件
吴文力 · 2006-01-09 · via 博客园 - 吴文力

下面的代码说明了怎样在一个给定的目录中从上到下地搜索整个目录树.本例子只将结果输出到system debug screen.

调用下面的类函数,搜索完成之后,将出现一个信息框.

void CTestView::OnSearch() 
{

// szFilename is declared in the header as array of char
// look for MyFile.txt (or whatever)

strcpy(szFilename,"MyFile.txt");

// go to root directory (or to whichever directory that you wish)

_chdir("C:\\");

// search for the filename

SearchDirectory();

// announce when done

MessageBox("Done Searching"); 
}

函数 SearchDirectory() 在函数 OnSearch()中被调用. SearchDirectory() 然后反复回调,直到整个目录,包括子目录都被搜索.

void CTestView::SearchDirectory() 
{
struct _finddata_t filestruct;
long hnd;
char buffer[_MAX_PATH];

// set _findfirst to find everthing

hnd = _findfirst("*",&filestruct);

// if handle fails, drive is empty...

if((hnd == -1)) return;

// get first entity on drive - check if it's a directory

if(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY 
&& !(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_HIDDEN)) { 

// if so, change to that directory and recursively call SearchDirectory

if(*filestruct.name != '.') { 

_chdir(filestruct.name);

SearchDirectory();

// go back up one directory level

_chdir("..");
}

else {

// if it's not a directory and it matches what you want...

if(!stricmp(filestruct.name,szFilename)) {

// output the filename with path to debugger

_getcwd(buffer,_MAX_PATH);
strcat(buffer,"\\");
strcat(buffer,filestruct.name); 
strcat(buffer,"\r\n");
OutputDebugString(buffer);

}

while(!(_findnext(hnd,&filestruct))) {

if(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY 
&& !(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_HIDDEN)) {

if(*filestruct.name != '.') { 
_chdir(filestruct.name);

SearchDirectory();

_chdir("..");
}
}
else {

if(!stricmp(filestruct.name,szFilename)) {
_getcwd(buffer,_MAX_PATH); 
strcat(buffer,"\\");
strcat(buffer,filestruct.name);
strcat(buffer,"\r\n");
OutputDebugString(buffer);
}
}
}

_findclose(hnd); 
}