.
사용자가 원하는대로 확장 기능에 대해 반환 된 문자열의 끝을 확인하면서 이러한 함수를 반복하는 것입니다. 같은
뭔가 : 언급 한 바와 같이
char *fspec = findfirst("/tmp");
while (fspec != NULL) {
int len = strlen (fspec);
if (len >= 4) {
if (strcmp (".foo", fspec + len - 4) == 0) {
printf ("%s\n", fspec);
}
}
fspec = findnext();
}
은, 실제 함수를 사용하면 디렉토리를 탐색에 사용할는 OS 별입니다.
UNIX의 경우 거의 확실하게 opendir, readdir 및 closedir이 사용됩니다. 이 코드는 그 시작을위한 좋은 출발점입니다 :
#include <dirent.h>
int len;
struct dirent *pDirent;
DIR *pDir;
pDir = opendir("/tmp");
if (pDir != NULL) {
while ((pDirent = readdir(pDir)) != NULL) {
len = strlen (pDirent->d_name);
if (len >= 4) {
if (strcmp (".foo", &(pDirent->d_name[len - 4])) == 0) {
printf ("%s\n", pDirent->d_name);
}
}
}
closedir (pDir);
}
어떤 운영체제입니까? –
UNIX 운영 체제 – Alex