//windows
#include <stdio.h>
#include <io.h>
#include <string>
int main()
{
std::string sPath = "c://test//*.*";
_finddata_t file;
long lHandle;
if((lHandle = _findfirst(sDir.c_str(), &file)) == -1L)
{
printf("can not find file!/n");
return -1;
}
while(_findnext(lHandle, &file) == 0)
{
std::string s(file.name);
std::string::size_type pos;
if(std::string::npos != pos)
{
printf("file name:%s /n", s.substr(0, pos));
}
}
}
//linux
#include "stdio.h"
#include "dirent.h"
#include <string>
int main()
{
std::string sPath = "/home/test/";
struct dirent* pDirent = NULL;
DIR* pDir;
if(!(pDir = opendir(sDir.c_str())))
{
printf("can not open dir /n");
return -1;
}
while((ptr = readdir(dir)) != NULL)
{
std::string sName(pDirent->d_name);
std::string::size_type pos;
}
}
if(std::string::npos != pos)
{
printf("file name:%s /n", sName.substr(0, pos));
}