在这个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(). 我认为,返回当前目录中所有文件的链接列表。 那么,我发现不是这样,我真的很感谢在这个问题上的一些帮助。 我期待一个链接列表被返回,然后我将遍历它来find匹配的文件名(最终目标)的文件。 但是,现在,我只是试图遍历链表(婴儿的步骤)。 现在,它将返回一个文件,然后退出循环。 这对我来说没有意义。 任何帮助将非常感谢!
文件系统的开放:
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:%sn",strerror(errno),getprogname()); exit(EXIT_FAILURE); }/*Ends the files system check if statement*/ /*displays the @R_120_4045@ion about the specified file.*/ file_ls(file_system,name,flags);
为了说明起见,directory_nameparsing来自用户的inputpath,并返回类似/ home / tpar44的内容。 那个目录然后打开。
在文件系统内search:
Java文件pathWindows / Linux
使用robo复制和过程的文件复制
是Windows XP中的文件创buildprimefaces?
在c#中读取扩展图像属性
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 = %sn",parent->fts_name); parent = parent->fts_link; } }
谢谢!
File.copy以及作为stream打开的文件,并写入networking文件挂起到本地机器
GENERIC_ALL和文件夹/文件ACL? GENERIC_ALL真的做什么?
窗体执行一个batch file
我认为这完全是由设计。
…也就是说,为fts_open()指定的参数…
它说的是,它会列出path_argv参数中的根元素为您的方便。 它将path_argv数组视为逻辑目录本身。
换句话说这个:
int main(int argc,char* const argv[]) { char* const path[] = { ".","/home","more/root/paths",NULL }; FTS* file_system = fts_open(path,FTS_COMFOLLOW | FTS_NOCHDIR,&compare); if (file_system) { file_ls(file_system,"",0); fts_close(file_system); } return 0; }
会输出
parent = . parent = /home parent = more/root/paths
其实,它确实(见http://liveworkspace.org/code/c2d794117eae2d8af1166ccd620d29eb )。
#include<stdlib.h> #include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<fts.h> #include<string.h> #include<errno.h> int compare (const FTSENT**,const FTSENT**); void file_ls(FTS* file_system,const char* file_name,int* flags) { FTSENT* node = fts_children(file_system,0); if (errno != 0) perror("fts_children"); while (node != NULL) { // Todo use file_name and flags printf("found: %s%sn",node->fts_path,node->fts_name); node = node->fts_link; } } int main(int argc,char* const argv[]) { FTS* file_system = NULL; FTSENT* node = NULL; if (argc<2) { printf("Usage: %s <path-spec>n",argv[0]); exit(255); } char* const path[] = { argv[1],NULL }; const char* name = "some_name"; file_system = fts_open(path,0); // shows roots while( (node = fts_read(file_system)) != NULL) file_ls(file_system,0); // shows child elements fts_close(file_system); } return 0; } int compare(const FTSENT** one,const FTSENT** two) { return (strcmp((*one)->fts_name,(*two)->fts_name)); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。