How can I get the list of files in a directory using C or C++?

前端 未结 27 3231
情书的邮戳
情书的邮戳 2020-11-21 05:30

How can I determine the list of files in a directory from inside my C or C++ code?

I\'m not allowed to execute the ls command and parse the results from

27条回答
  •  执念已碎
    2020-11-21 06:13

    #include
    #include 
    using namespace std;
    char ROOT[]={'.'};
    
    void listfiles(char* path){
        DIR * dirp = opendir(path);
        dirent * dp;
        while ( (dp = readdir(dirp)) !=NULL ) {
             cout << dp->d_name << " size " << dp->d_reclen<1) path=argv[1]; else path=ROOT;
    
        cout<<"list files in ["<

提交回复
热议问题