请问怎样遍历同一个目录下的所有相同类型的文件?

gully 2002-03-16 06:44:29
比如:
在c:\web\*.html
最好不调用win-api
...全文
32 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
strip 2002-03-16
  • 打赏
  • 举报
回复
给你一个sample
#include <stdlib.h>
#include <direct.h>
#include <io.h>
void findfiles( char* path, char* filter )
{
struct _finddata_t c_file;

char oldworkpath[_MAX_PATH];
_getcwd( oldworkpath, _MAX_PATH ); // ±£´æµ±Ç°¹¤×÷·¾¶

_chdir( path );

long hFile;
if( (hFile = _findfirst( filter, &c_file )) == -1L )
{
// there is no file
}
else
{
printf( "%s\n", c_file.name );
while( _findnext( hFile, &c_file ) == 0 )
{
printf( "%s\n", c_file.name );
}
_findclose( hFile );
}
_chdir( oldworkpath );
return;
}
int main(int argc, char* argv[])
{
findfiles( "c:\\download", "*.exe" );
return 0;
}
strip 2002-03-16
  • 打赏
  • 举报
回复
那就用c函数: _findfirst/_findnext
Wugifer 2002-03-16
  • 打赏
  • 举报
回复
_findfirst
&
_findnext

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧