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

推荐订阅源

The Hacker News
The Hacker News
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
L
LangChain Blog
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
F
Full Disclosure
T
The Blog of Author Tim Ferriss
月光博客
月光博客
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
博客园 - Franky
B
Blog
博客园_首页
C
CERT Recently Published Vulnerability Notes
Hugging Face - Blog
Hugging Face - Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
I
Intezer
P
Proofpoint News Feed
博客园 - 叶小钗
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Recorded Future
Recorded Future
NISL@THU
NISL@THU
A
Arctic Wolf
Know Your Adversary
Know Your Adversary
C
Cyber Attacks, Cyber Crime and Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
C
Cisco Blogs
大猫的无限游戏
大猫的无限游戏
S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
Forbes - Security
Forbes - Security
Project Zero
Project Zero
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cisco Talos Blog
Cisco Talos Blog
D
Docker
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理

博客园 - 吴文力

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