现在的位置: 首页 > 综合 > 正文

遍历目录又一C

2012年01月14日 ⁄ 综合 ⁄ 共 749字 ⁄ 字号 评论关闭

[code]void scanAllFiles( char *filePath )
{
struct _finddata_t fileInfo;
int done;
char filePathCpy[MAX_PATH];

strcpy( filePathCpy, filePath );
done = _findfirst( filePath, &fileInfo );
if( done == -1 )  //打开路径失败返回
{
          return;
}
   
int tag=0;
    while( tag != -1 ) //从第一个文件..第N个文件
{
if( !strcmp( fileInfo.name, "." ) || !strcmp( fileInfo.name, ".." ) )
{
tag=_findnext( done, &fileInfo ); //查找下一个配匹的文件
continue;
}

//取得全路径
        char fullPath[ MAX_PATH ];
strcpy( fullPath, filePathCpy );
fullPath[ strlen( fullPath ) - strlen( "*" ) ] = '\0';//去掉\\*
strcat( fullPath, fileInfo.name );
       
if ( fileInfo.attrib & _A_SUBDIR ) //是一个文件夹
{
        strcat( fullPath, "\\*" );
            scanAllFiles( fullPath ); //递归扫描该文件夹的子文件
}
else
{
              printf("%s\n", fileInfo.name );
}
tag=_findnext(done,&fileInfo); //查找下一个配匹的文件
}
_findclose(done);
}
[/code]

抱歉!评论已关闭.