简单的一个whereis的实现,代码如下:

 #include <stdio.h>
#include <errno.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
void dir_scan(char *path, char *file, char * fileToSearch);
int count = ; int main(int argc, char *argv[])
{
struct stat s;
if(argc != ){
printf("error argu!");
exit();
}
if(lstat(argv[], &s) < ){
printf("lstat error!");
exit();
}
if(!S_ISDIR(s.st_mode)){
printf("This is not a dir name!\n");
exit();
}
dir_scan("", argv[], argv[]);
exit();
} void dir_scan(char * path, char * file, char * fileToSearch)
{
struct stat s;
DIR * dirPtr;
struct dirent * dtPtr;
char dirName[];
memset(dirName, , * sizeof(char));
strcpy(dirName, path); if(lstat(file, &s) < ){
printf("asdasdad");
// fprintf(stdout, "The reason is %s\t ", strerror(errno));
exit(());
}
if(S_ISDIR(s.st_mode)){
strcat(dirName, file);
strcat(dirName, "/");
// printf("now the dir name is %s\n", file);
if((dirPtr = opendir(file)) == NULL){
printf("open dir error!\n");
exit();
printf("The count now is %d\n", count);
}
if(chdir(file) < ){
printf("chdir error!\n");
exit();
}
while((dtPtr = readdir(dirPtr)) != NULL){
if(dtPtr->d_name[] == '.')
continue;
dir_scan(dirName, dtPtr->d_name, fileToSearch);
}
if(dirPtr != NULL)
closedir(dirPtr);
if(chdir("..") < ){
printf("chdir error!\n");
exit();
}
}else{
if(strstr(file, fileToSearch) != NULL && (!strstr(file, "."))){
printf("%s%s\n", dirName, file);
// printf("adasdadad\n");
}
count++;
}
}

最新文章

  1. Eclipse 使用技巧
  2. *POJ 1222 高斯消元
  3. iar 错误解决
  4. Tomcat启动后快逸报表报错的解决方法
  5. [原]如何在Android用FFmpeg+SDL2.0解码声音
  6. MySQL添加字段和删除字段
  7. 关于C++对汉字拼音的处理——终结篇
  8. 网页增重不可控?试试 OneAPM Cloud Test
  9. android-意图Intent
  10. PHPCMS快速建站系列之自定义分页函数
  11. docker 常用命令和常用容器启动
  12. List的分组,求和,过滤操作
  13. Froms 认证 二级域名共享session登录凭证
  14. 解决代理池的问题AttributeError: &#39;int&#39; object has no attribute &#39;items&#39;
  15. 大众点评selfxss结合两个csrf变废为宝(已修复,故公开,不涉及真实参数)
  16. H5自动准备杂记
  17. Ubuntu 14.04 LTS 安装Docker(转)
  18. 大数据入门第二十二天——spark(二)RDD算子(2)与spark其它特性
  19. 洛谷P3613 睡觉困难综合征(LCT,贪心)
  20. R 语言 相关入门资料

热门文章

  1. 启动一个支持文件上传的HTTP-Server
  2. MariaDB备份和恢复
  3. [DevOps] 认识一下
  4. Flume日志收集 总结
  5. Python(变量、数据类型)
  6. Android 电池关机充电
  7. Linux图形化界面下使用命令进行截图的方法
  8. Maven 的41种骨架功能介绍
  9. Intellij IDear关闭页面浏览器显示图标
  10. js异步获取数据的问题