易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++中关于遍历文件夹的操作

#include <windows.h>
#include <stdio.h>
void FindFileInDir(char* rootDir, char* strRet)
{
char fname[256];
ZeroMemory(fname,256);
WIN32_FIND_DATA fd;
ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
HANDLE hSearch;
char filePathName[256];
char tmpPath[256];
ZeroMemory(filePathName, 256);
ZeroMemory(tmpPath, 256);
strcpy(filePathName, 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);
strcat(tmpPath, fd.cFileName);
FindFileInDir(tmpPath, strRet);
}
else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
sprintf(fname, "%-50.50s", fd.cFileName);
strcat(strRet + strRet[strlen(strRet)] , fname);
}
while( !bSearchFinished )
{
if( FindNextFile(hSearch, &fd) )
{
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
strcpy(tmpPath, rootDir);
strcat(tmpPath, fd.cFileName);
FindFileInDir(tmpPath, strRet);
}
else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
sprintf(fname, "%-50.50s", fd.cFileName);
strcat(strRet + strRet[strlen(strRet)] , fname);
}
}
else
{
if( GetLastError() == ERROR_NO_MORE_FILES ) //Normal Finished
{
bSearchFinished = TRUE;
}
else
bSearchFinished = TRUE; //Terminate Search
}
}
FindClose(hSearch);
}
main()
{
}

把这段代码复制 另存为后缀为 .CPP 文件 然后编译 可以编译
在来看看你的那个
花了几分钟改成了 C语言
贴出来了
你把下边的代码复制
另存为后缀为 .C 的文件
然后 编译 就可以了
#include <windows.h>
#include <stdio.h>
void FindFileInDir(char* rootDir, char* strRet)
{
char fname[256];
WIN32_FIN


相关文档:

UVa Online Judge Volume C 题目和解答索引

UVa Online Judge - Volume C 题目和解答索引。前面为原题链接,后面为我的解答链接。
返回总目录
10003 - Cutting Sticks
Dynamic Programming
Solution
10004 - Bicoloring
Graph: BFS
Solution
10006 - Carmichael Numbers
Number Theory: Modulus
Solution
10010 - Where's Waldorf?
String
Solution ......

c/c++语言问题中可变参数


 va_list是c/c++语言问题中解决可变参数的一组宏.先来看一个程序例子吧.
view plaincopy to clipboardprint?
#include <stdarg.h>   
/** 函数名:max  
  * 功能:返回n个整数中的最大值  
  *  参数:num:整数的个数 . ......

keil c union 存储的问题

     3: int main()
     4: {
     5:    int i = 1,j;
     6:    union test{
     7:       int m;
     8:  ......

【C\C++语言入门篇】 调试基础

通过前面两篇,相信大家已经基本了解了我们的研究思路。既然是研究,那么必须的研究工具就得熟练掌握了。这里我所指的研究工具就是VC,我所使用的VC版本是2005。本文也将根据VC2005进行探讨。可能很多朋友或者初学者还是使用的VC6.0。在这里本人不推荐使用VC6.0。原因很简单,VC6.0已经过时了,后面的版本比VC6.0更强大方便 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号