⑴ C璇璦linux綆鍗曠紪紼嬶紝閬嶅巻鏂囦歡澶硅幏寰楁枃浠跺悕錛岃皟璇曚笉瀵癸紝奼傚姪錛侊紒璋㈣阿錛侊紒
opendir() 鐨勫弬鏁頒笉瀵廣備笉搴旇ユ槸鏈夐氶厤絎︾殑*.jp2褰㈠紡錛岃屽簲璇ユ槸涓涓鎸囧畾鐨勭洰褰曘
鐪嬩綘鐨勯渶奼傛弿榪幫紝寤鴻浣犵敤scandir鍑芥暟錛屽彲鑳芥洿鏂逛究涓浜涖
scandir鍙浠ユ寚瀹氫竴涓猣ilter銆傚彧榪斿洖婊¤凍鏉′歡鐨勯」鐩銆
涓嬮潰鏄鍙傝僱inux涓璼candir man page 閲岀殑渚嬪瓙鍐欑殑涓孌靛弬鑰冧唬鐮併
#include <dirent.h>
int myfilter(const struct dirent *)
{
// 濡傛灉鏂囦歡浠0寮澶翠笖鏈.jp2鍚庣紑錛岃繑鍥1
// 鍚﹀垯 榪斿洖0
}
main(){
struct dirent **namelist;
int n;
n = scandir(DIRNAME, &namelist, myfilter, alphasort);
if (n < 0)
perror("scandir");
else {
while(n--) {
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}
⑵ LINUX編程中scandir中的versionsort項, 總是出錯
用gcc試試,versionsort是gcc的