java获取文件目录列表_获取目录中的文件列表

我正在开发一个C项目,我需要获取目录中的文件列表 . 我正在使用dirent.h但是在使用它时遇到了一些问题,我正在Linux下构建程序 .

当我尝试构建程序时,我收到以下错误

myClass:error: âDIRâ undeclared (first use in this function)

myClass:408: error: (Each undeclared identifier is reported only once

myClass:408: error: for each function it appears in.)

myClass:408: error: âdirâ undeclared (first use in this function)

myClass:410: warning: implicit declaration of function âopendirâ

myClass:413: warning: implicit declaration of function âreaddirâ

myClass:413: warning: assignment makes pointer from integer without a cast

myClass:415: error: dereferencing pointer to incomplete type

myClass:417: warning: implicit declaration of function âclosedirâ

下面是我正在使用的代码

int logMaintenance(void *arg)

{

DIR *dir;

struct dirent *ent;

dir = opendir(directory);

if (dir != NULL)

{

while ((ent = readdir (dir)) != NULL)

{

printf("%s\n", ent->d_name);

}

closedir(dir);

}

else

{

printf("Failed to read directory %i", EXIT_FAILURE);

}

return 0;

}

我不明白这些错误是什么意思,特别是当我说我已经包含了针对Liunux的dirent.h头文件时DIR是未声明的 .

谢谢你的帮助 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值