2012-09-27 3 views
0

이 설명서 페이지 fts_children() referenced에 문제가 있습니다. http://www.kernel.org/doc/man-pages/online/pages/man3/fts.3.html. fts_children()은 하위 디렉토리에있는 모든 파일을 맨 페이지에 있다고 주장하는 것처럼 보이지 않습니다. 예를 들어, temp이라는 파일을 많은 파일이있는 v2 폴더에 있습니다. 알파벳순으로 첫 번째 파일을 제외하고 하위 디렉토리에있는 모든 파일을 가져옵니다. 이것에 대해 할 수있는 일이 있습니까? 내 코드는 아래에 있으며 권한이있는 하위 디렉토리의 파일입니다. 코드 : 온도의fts_children() 작동하지 않음

int compare (const FTSENT**, const FTSENT**); 

int main(int argc, char* const argv[]) 
{ 
    FTS* file_system = NULL; 
    FTSENT* child = NULL; 
    FTSENT* parent = NULL; 

    file_system = fts_open(argv + 1,FTS_COMFOLLOW | FTS_NOCHDIR,&compare); 

    if (NULL != file_system) 
    { 
     while((parent = fts_read(file_system)) != NULL) 
     { 

      child = fts_children(file_system,0); 
      if (errno != 0) 


     while ((NULL != child) && (NULL != child->fts_link)) 

      { 
       child = child->fts_link; 
       printf("%s\n", child->fts_name); 
      } 

     } 
     fts_close(file_system); 
    } 
    return 0; 
} 

int compare(const FTSENT** one, const FTSENT** two) 
{ 
    return (strcmp((*one)->fts_name, (*two)->fts_name)); 
} 

파일 (ls -l 명령으로 출력) :

total 8 
-rwxrwxrwx 1 tparisi student 14 Sep 27 13:05 a 
-rw-r--r--+ 1 tparisi student 25 Sep 26 14:42 f 
-rw-r--r--+ 1 tparisi student 13 Sep 27 11:28 file2 
-rw-r--r--+ 1 tparisi student 14 Sep 27 11:42 files 
drwxr-xr-x+ 2 tparisi student 3 Sep 27 13:33 temp2 
-rw-r--r--+ 1 tparisi student 14 Sep 27 13:04 test 
-rw-r--r--+ 1 tparisi student 5 Sep 27 13:23 z 

전체 디렉토리 내 프로그램을 실행할 때 a에 대한 동의를 인쇄됩니다.

도움이 될 것입니다. 감사합니다. 반환 된 목록을 통과 할 때

답변

1

당신은 첫 번째 항목을 건너 :

while ((NULL != child) && (NULL != child->fts_link)) 
{ 
    child = child->fts_link; 
    printf("%s\n", child->fts_name); 
} 

가 인쇄 반환 된 목록에서 모든 파일을 얻을 수

while(child) 
{ 
    printf("%s\n", child->fts_name); 
    child = child->fts_link; 
} 

을보십시오.

+0

와우, 나는 어리 석다. 나는 지금 이것을 몇 시간 동안 알아 내려고 노력했다. 나는 내가 상급의 순간을 가졌다고 생각한다. 감사! – tpar44

+0

바보가 아니고, 카페인이 부족하면 우리 모두에게 그렇게됩니다. –