如何使用C或C++获取目录中的文件列表?
让我们考虑以下 C++ 示例代码来获取目录中的文件列表。
算法
Begin Declare a poniter dr to the DIR type. Declare another pointer en of the dirent structure. Call opendir() function to open all file in present directory. Initialize dr pointer as dr = opendir("."). If(dr) while ((en = readdir(dr)) != NULL) print all the file name using en->d_name. call closedir() function to close the directory. End.登录后复制