博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
windows linux—unix 跨平台通信集成控制系统----文件搜索
阅读量:4572 次
发布时间:2019-06-08

本文共 3319 字,大约阅读时间需要 11 分钟。

跨平台的网络通信,跟设备的集成控制,牵扯到在各种平台下的文件搜索问题,windows下面的已经有了。

地址如下:

 

这篇文章主要介绍一下linux下面的文件搜索实现:

Filesearch.h

////  Filesearch.h//  ////  Created by mac mac on 13-4-28.//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.//#ifndef _Filesearch_h#define _Filesearch_h//#include 
//#include
#include
#include
#include
#include
#include
//#include
#include
#include "mac.h"#include "Socket.h"//#define MAX_PATH 255int IsDir(char *name);void Search_File(char *path,char *name);//int search_flag = 0;/* int main(int argc , char *argv[]){ static char *current_dir; static char *file_name; int length; if(argc==1) { printf("it takes more parameter!!!n"); } if(argc==2) { current_dir = (char *)getcwd(current_dir,MAX_PATH); } if(argc==3) { length = strlen(argv[1]); if(length>1 && (argv[1][length-1]=='/')) { argv[1][length-1]=='�'; } current_dir = argv[1]; file_name = argv[2]; } Search_File(current_dir,file_name); printf("Hello world!n"); return 0;} */#endif

Filesearch.cpp:

////  Filesearch.cpp//  mac_client////  Created by mac mac on 13-5-21.//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.//#include 
#include
#include "Filesearch.h"int search_flag = 0;int IsDir(char *name){ struct stat buff; if(lstat(name,&buff)<0) return 0; return S_ISDIR(buff.st_mode);}//调用的时候直接使用'/'目录作为搜索路径,相当于搜索全盘了。void Search_File(char *path,char *name){ DIR *directory; struct dirent *dir_entry; char buffer[MAX_PATH]; if((directory = opendir(path)) == NULL) { fprintf(stderr,"%s",path); printf(path); perror(" "); return; } while(dir_entry == readdir(directory)) { if(!strcmp(dir_entry->d_name,".")||!strcmp(dir_entry->d_name,"..")) { //do nothing } else { if((strcmp(path,"/")) == 0) { sprintf(buffer,"%s%s",path,dir_entry->d_name); // printf(buffer); /* if is not boot directory do not add "/"*/ } else { sprintf(buffer,"%s/%s",path,dir_entry->d_name); printf(buffer); printf("\n"); } if(IsDir(buffer)) { Search_File(buffer,name); } else { //find the file,if exist if(strcmp(dir_entry->d_name,name)==0) { printf("%sn",buffer); search_flag=1; } } } } closedir(directory);}void setOutFiles(const char * path)//得到指定目录下面所有文件, 传输的时候还得改{ DIR *dp; struct dirent *dirp; char fullpath[MAX_PATH] = {0}; if((dp = opendir(path)) == NULL) { //err_quit(); return ; } if (strcmp(path,"/") == 0) //如果是根目录,要处理一下 { while((dirp = readdir(dp))!= NULL) { sprintf(fullpath,"%s%s", path,dirp->d_name); printf("%s\n",fullpath); } } else { while((dirp = readdir(dp))!= NULL) { sprintf(fullpath,"%s/%s", path,dirp->d_name); printf("%s\n",fullpath); } }}

 

 

搭建传输的socket平台参考下面博文:

 

 

转载于:https://www.cnblogs.com/wuyida/p/6301382.html

你可能感兴趣的文章
程序员眼睛的保护(爱护眼睛,你我做起)
查看>>
Python之路【第六篇】:socket
查看>>
android的用户定位(一)
查看>>
Java 多生产者消费者问题
查看>>
常用的JS技术1
查看>>
商品搜索
查看>>
upc 9519 New Game
查看>>
oracle 用sql实现密码的加密,解密
查看>>
各种蒟蒻模板【如此简单】
查看>>
搜索1016
查看>>
配置算法(第4版)的Java编译环境
查看>>
PostgreSQL 9.6.0 手册
查看>>
编写带有点击特效的UIButton
查看>>
使用mac版思维导图软件MindNode
查看>>
理解面向对象编程(OOP Object Oriented Programming)
查看>>
[題解]luogu_P1144最短路計數
查看>>
每日一个linux命令5 -- rm
查看>>
外存===内存
查看>>
node.js中的fs.appendFile方法使用说明
查看>>
URAL 1297 求最长回文字符串
查看>>