代码实现如下:
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
int main(int argc,char* argv[])
//int main()
{
DIR *dp;
struct dirent *dirp;
dp=opendir(".");
if(argc!=2)
{
printf("Big Warning:We need two parameters.Another is the dir.\n");
return 0;
}
if((dp=opendir(argv[1]))==NULL)
{
printf("It is a super awkward!The dir wrong!\n");
// exit(0);
return 0;
}
while((dirp=readdir(dp))!=NULL)
{
printf("%s ",dirp->d_name);
}
puts("");
closedir(dp);
return 0;
}
依据代码可以实现显示任意一个文件夹中的所有文件的内容,只需要给出正确的路径即可