⑴ 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的