作者:翟峰 | 来源:互联网 | 2023-07-26 07:25
#include
#include
/*struct dirent
{
long d_ino; // inode number 索引节点号
off_t d_off; // offset to this dirent 在目录文件中的偏移
unsigned short d_reclen; // length of this d_name 文件名长
unsigned char d_type; // the type of d_name 文件类型
char d_name [NAME_MAX+1]; // file name (null-terminated) 文件名,最长255字符
}
其中d_type表明该文件的类型:文件(8)、目录(4)、链接文件(10)等
*/
int main(){
DIR *directory_pointer;
struct dirent *entry;
if((directory_pointer=opendir("/home/libin/桌面"))==NULL){
printf("Error open\n");
return ;
} else {
while((entry=readdir(directory_pointer))!=NULL){
if(entry->d_name[0]=='.') continue;
printf("%s\n",entry->d_name);
}
}
return 0;
}