#include <stdio.h> #include <string.h> #include <io.h> #include <direct.h> const int kMaxNum = 256; // 最大文件个数 const int kMaxLength = 20; // 文件名的最大长度 char fileName[kMaxNum][kMaxLength]; int fileNum = 0; // 文件个数-1 // 获取目录文件名,并存在二维数组里面 void GetDirFiles(const char *dir) { long file; struct _finddata_t find; _chdir("d://"); if((file=_findfirst("*.*", &find))==-1L) { printf("空白!/n"); return; } fileNum = 0; strcpy(fileName[fileNum], find.name); while(_findnext(file, &find)==0) { ++fileNum; strcpy(fileName[fileNum], find.name); } _findclose(file); } int main() { int i; GetDirFiles("c://"); for (i = 0; i <= fileNum; ++i) { printf("%s/n", fileName[i]); } return 0; }