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

推荐订阅源

S
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
A
Arctic Wolf
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
Latest news
Latest news
Help Net Security
Help Net Security
S
Security Affairs
Webroot Blog
Webroot Blog
The Hacker News
The Hacker News
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tor Project blog
Forbes - Security
Forbes - Security
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Help Net Security
L
Lohrmann on Cybersecurity
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
MongoDB | Blog
MongoDB | Blog
Cyberwarzone
Cyberwarzone
The Last Watchdog
The Last Watchdog
S
Securelist
N
News and Events Feed by Topic
S
Secure Thoughts
F
Fortinet All Blogs
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
M
MIT News - Artificial intelligence
F
Full Disclosure
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
P
Privacy International News Feed
L
LangChain Blog
Know Your Adversary
Know Your Adversary
C
CERT Recently Published Vulnerability Notes

博客园 - 吴文力

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); 
}