23,116
社区成员
发帖
与我相关
我的任务
分享
char dirPath[BUFF_SIZE] = {"/home/doc/"};
DIR* dp = opendir(DIR_PATH);
struct dirent* dir;
while((dir = readdir(dp)) != NULL)
{
int len = strlen(dir->d_name) + strlen(dirPath) + 1;
char fileName[len];
strncpy(fileName,dirPath,strlen(dirPath)+1);
strcat(fileName,dir->d_name);
printf("%s\n",fileName);
}
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
int main(int argc , char* argv[])
{
if(argc != 2)
{
printf("The Wrong Count Of Argument.\n");
exit(1);
}
DIR* dp = opendir(argv[1]);
struct dirent* dirs;
while ((dirs = readdir(dp)) != NULL)
{
printf("%s\n",dirs->d_name);
}
exit(0);
}