windows下遍历文件夹下的文件

#include
#include
#include
using namespace std;
int ReadStationID(char(*id)[50])
{
struct _finddata_t c_file;
long hFile;
char *p = NULL;
int i = 0;
/* Find first .c file in current directory */
if ((hFile = _findfirst("E:\\KJ_WORKDIR\\usr\\callsc_mtv\\zjcfgmn\\Station\\*.txt", &c_file)) == -1L)
{
printf("No *.txt files in current directory!\n");
return -1;
}
if (c_file.name)
sprintf(id[i++], "%s", strtok(c_file.name, "."));
while (_findnext(hFile, &c_file) == 0)
{
sprintf(id[i++], "%s", strtok(c_file.name, "."));
//printf(" %s\n", c_file.name);
}
_findclose(hFile);
return 0;
}
int main()
{
char id[50][50] = {0};
ReadStationID(id);
for(int i = 0; i< 50; i++)
{
cout << id[i] << endl;
}
}

你可能感兴趣的:(windows下遍历文件夹下的文件)