How do I get a list of files in a directory in C++?

后端 未结 13 1458
南旧
南旧 2020-11-28 23:36

How do you get a list of files within a directory so each can be processed?

13条回答
  •  情歌与酒
    2020-11-28 23:58

    Here's an example in C on Linux. That's if, you're on Linux and don't mind doing this small bit in ANSI C.

    #include 
    
    DIR *dpdf;
    struct dirent *epdf;
    
    dpdf = opendir("./");
    if (dpdf != NULL){
       while (epdf = readdir(dpdf)){
          printf("Filename: %s",epdf->d_name);
          // std::cout << epdf->d_name << std::endl;
       }
    }
    closedir(dpdf);
    

提交回复
热议问题