windows linux—unix 跨平台通信集成控制系统----文件搜索

简介: 跨平台的网络通信,跟设备的集成控制,牵扯到在各种平台下的文件搜索问题,windows下面的已经有了。 地址如下: http://blog.csdn.net/wangyaninglm/article/details/8668132   这篇文章主要介绍一下linux下面的文件搜索实现: Filesearch.

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

地址如下:

http://blog.csdn.net/wangyaninglm/article/details/8668132

 

这篇文章主要介绍一下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 <stdio.h>
//#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <unistd.h>
//#include <string.h>
#include <time.h>
#include "mac.h"
#include "Socket.h"


//#define MAX_PATH 255



int 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 <stdio.h>
#include <iostream>
#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平台参考下面博文:

 

http://blog.csdn.net/wangyaninglm/article/details/41940287

 

相关文章
|
11天前
|
C# Windows
.NET开源免费的Windows快速文件搜索和应用程序启动器
今天大姚给大家分享一款.NET开源(MIT License)、免费、功能强大的Windows快速文件搜索和应用程序启动器:Flow Launcher。
|
1月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
|
1月前
|
安全 Linux Shell
全面对比linux和windows,选择哪个系统比较好
全面对比linux和windows,选择哪个系统比较好
64 0
|
1月前
|
存储 安全 数据安全/隐私保护
Windows部署WebDAV服务并映射到本地盘符实现公网访问本地存储文件
Windows部署WebDAV服务并映射到本地盘符实现公网访问本地存储文件
251 0
|
28天前
|
存储 Shell Linux
【Shell 命令集合 网络通讯 】Linux 显示Unix-to-Unix Copy (UUCP) 系统的状态信息 uustat命令 使用指南
【Shell 命令集合 网络通讯 】Linux 显示Unix-to-Unix Copy (UUCP) 系统的状态信息 uustat命令 使用指南
26 0
|
27天前
|
开发框架 数据安全/隐私保护 开发者
HBuilder开发者必备!Windows上传IPA文件的软件分享
HBuilder开发者必备!Windows上传IPA文件的软件分享
21 1
|
4天前
|
SQL 监控 安全
Linux&Windows 日志分析 陇剑杯 CTF
Linux&Windows 日志分析 陇剑杯 CTF
29 0
|
7天前
|
Windows
【Windows】 手写脚本更快编辑hosts文件
【Windows】 手写脚本更快编辑hosts文件
9 0
|
14天前
|
安全 Ubuntu Linux
Linux远程访问Windows实现步骤
在Windows上启用远程桌面连接并获取IP地址后,Linux用户需安装SSH客户端( Debian系:`sudo apt-get update; sudo apt-get install openssh-client`,RPM系:`sudo yum install openssh-clients`)。然后使用命令`ssh 用户名@Windows_IP地址`连接,其中`用户名`和`Windows_IP地址`按实际情况填写。
14 4
|
25天前
|
缓存 Linux iOS开发
【C/C++ 集成内存调试、内存泄漏检测和性能分析的工具 Valgrind 】Linux 下 Valgrind 工具的全面使用指南
【C/C++ 集成内存调试、内存泄漏检测和性能分析的工具 Valgrind 】Linux 下 Valgrind 工具的全面使用指南
62 1

热门文章

最新文章