この fts_children() の質問に頭を悩ませています。man ページhttp://www.kernel.org/doc/man-pages/online/pages/man3/fts.3.htmlでは、As a special case, if fts_read() has not yet been called for a hierarchy,
fts_children() will return a pointer to the files in the logical directory
specified to fts_open(), that is, the arguments specified to fts_open().
どのファイルがリンクされたリストであるかを明確に示しています。現在のディレクトリが返されます。そうではないことがわかりました。この問題について何か助けていただければ幸いです。リンクされたリストが返されることを期待していたので、それを繰り返し処理して、一致するファイル名 (最終目標) を持つファイルを見つけました。ただし、現在、リンクされたリストを繰り返し処理しようとしています (ベイビーステップ)。現在、1 つのファイルを返し、ループを終了します。これは私には意味がありません。どんな助けでも大歓迎です!!!
ファイルシステムのオープン:
char* const path[PATH_MAX] = {directory_name(argv[argc-index]), NULL};
char* name = file_name(argv[argc-index]);
if ((file_system = fts_open(path, FTS_COMFOLLOW, NULL)) == NULL){
fprintf(stderr,"%s:%s\n", strerror(errno), getprogname());
exit(EXIT_FAILURE);
}/*Ends the files system check if statement*/
/*Displays the information about the specified file.*/
file_ls(file_system,name, flags);
明確にするために、directory_name はユーザーから入力されたパスを解析し、/home/tpar44 のようなものを返します。そのディレクトリが開かれます。
ファイルシステム内を検索:
void
file_ls(FTS* file_system, char* file_name, int* flags){
FTSENT* parent = NULL;
//dint stop = 0;
parent = fts_children(file_system, 0);
while( parent != NULL ){
printf("parent = %s\n", parent->fts_name);
parent = parent->fts_link;
}
}
ありがとう!