怎样一个一个的获得指定目录下的文件名.
怎样一个一个的获得指定目录下的文件名.
就是一次获得一个文件名,然后在获得一个文件名.知道目录下所有文件遍历完.
[解决办法]
查 MSDN: FindNextFile
[解决办法]
FindFirstFile和FindNextFile
[解决办法]
IShellFolder::EnumObjects
[解决办法]
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
void main( int argc,char * argv[] )
{
_finddata_t ft ;
char szPath[256] ;
int findresult,hs ;
printf( "Please input path: ");
puts(szPath);
sprintf(szPath, "%s\\*.* ",szPath) ;
findresult = _findfirst(szPath,&ft) ;
hs = findresult ;
while (findresult!=-1 )
{
unsigned char isdir = ft.attrib ;
isdir < <= 3 ;
isdir > > = 7 ;
if ( isdir )
{
printf( "%s <DIR> /n ",ft.name);
}
else
{
printf( "%s\n ",ft.name);
}
findresult = _findnext(hs,&ft) ;
}
}
[解决办法]
FindFirstFile和FindNextFile是Windows API,用C一样可以使用。
关键问题倒是:你的目标平台是Windows吗?有没有跨平台要求。
[解决办法]
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
void main( int argc,char * argv[] )
{
_finddata_t ft ;
char szPath[256] ;
int findresult,hs ;
printf( "Please input path: ");
fgets(szPath,13,stdin);
sprintf(szPath, "%s\\*.* ",szPath) ;
findresult = _findfirst(szPath,&ft) ;
hs = findresult ;
while (findresult!=-1 )
{
unsigned char isdir = ft.attrib ;
isdir < <= 3 ;
isdir > > = 7 ;
if ( isdir )
{
printf( "%s <DIR> \n ",ft.name);
}
else
{
printf( "%s\n ",ft.name);
}
findresult = _findnext(hs,&ft) ;
}
}
[解决办法]
fgets(szPath,13,stdin);
fgets里面的int 13为szpath的长度加1
[解决办法]
至少要使用个递归吧
[解决办法]
lz, FindFirst和FindNext是c的库函数。
[解决办法]
C难道不能调C++写的DLL么?