readdir()返回文件名时,stat()错误“没有此类文件或目录”
我无法确定统计信息引发的错误。下面的程序读取目录中的所有文件并打印文件名:
DIR *dp;struct dirent *dirp;struct stat sb;if((dp = opendir(argv[1]))==NULL){ perror("can't open dir");}while((dirp = readdir(dp))!=NULL){ if (stat(dirp->d_name, &sb) == -1) { perror("stat"); } printf("File name: %s \n",dirp->d_name);}
样本输出:
/home/eipe stat error: No such file or directoryFile name: copyofsample File name: a.out File name: . stat error: No such file or directoryFile name: udpclient.c File name: .. stat error: No such file or directoryFile name: client.c stat error: No such file or directoryFile name: ftpclient.c
这里是内容:
ls -l /home/eipe/c-rwxr-xr-x 1 eipe egroup 7751 2011-02-24 15:18 a.out-rw-r--r-- 1 eipe egroup 798 2011-02-24 13:50 client.c-rw-r--r-- 1 eipe egroup 15 2011-02-24 15:34 copyofsample-rw-r--r-- 1 eipe egroup 1795 2011-02-24 15:33 ftpclient.c-rw-r--r-- 1 eipe egroup 929 2011-02-24 13:34 udpclient.c
萧十郎
相关分类