对于这个 fts_children() 问题,我一直在敲我的头。在手册页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().
了我认为其中所有文件的链接列表返回当前目录。好吧,我发现情况并非如此,我非常感谢在这件事上提供一些帮助。我希望返回一个链接列表,然后我会遍历它以找到具有匹配文件名的文件(最终目标)。但是,现在,我只是想遍历链表(小步骤)。现在,它将返回一个文件,然后退出循环。这对我来说没有意义。任何帮助将不胜感激!!!
文件系统的打开:
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;
}
}
谢谢!