如何使用C或C++获取目录中的文件列表?

2023年 9月 22日 42.9k 0

如何使用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.

登录后复制

示例

#include
#include
#include
using namespace std;
int main(void) {
DIR *dr;
struct dirent *en;
dr = opendir("."); //open all directory
if (dr) {
while ((en = readdir(dr)) != NULL) {
cout

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论