#include<io.h>
{
char* fullname = "c:/";
struct _finddata_t filefind;
char curr[256],ret[1024];
int i,len,t=0;
memset(ret,0 ,1024);
sprintf(curr,"%s/*.*",fullname);
int handle,done;
if((handle=_findfirst(curr,&filefind))==-1) return S_OK;
while(!(done=_findnext(handle,&filefind)))
{
if(!strcmp(filefind.name,".."))continue;
if ((_A_SUBDIR==filefind.attrib))
{
len = strlen(filefind.name);
for(i=0;i<len;i++)
{
ret[t++] = filefind.name[i];
ret[t++] = 0;
}
ret[t++] = ':';
ret[t++] = 0;
}
}
_findclose(handle);
本文展示了一个使用 C 语言在 Windows 系统中遍历指定目录(如 C 盘)下所有子目录的方法。通过调用 _findfirst 和 _findnext 函数,可以有效地获取并打印出每个子目录的名称。
1272

被折叠的 条评论
为什么被折叠?



