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

 

相关文章
|
5月前
|
安全 Linux 生物认证
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
223 0
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
|
5月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
533 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
5月前
|
安全 Linux 生物认证
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
285 17
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
|
5月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
282 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
5月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
497 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
5月前
|
Linux 虚拟化 iOS开发
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
1059 0
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
|
5月前
|
Linux iOS开发 计算机视觉
GIMP 3.0.6 (Linux, macOS, Windows) 发布 - 免费开源图像编辑器
GIMP 3.0.6 (Linux, macOS, Windows) 发布 - 免费开源图像编辑器
385 0
|
Unix Shell Linux
在Unix/Linux操作系统中,Shell脚本广泛用于自动化任务
在Unix/Linux操作系统中,Shell脚本广泛用于自动化任务
262 2
|
安全 Unix Linux
Unix:Linux的“祖师爷”
Unix的诞生 Unix操作系统诞生于1969年,由肯·汤普逊(Kenneth Lane Thompson)和丹尼斯·里奇(Dennis MacAlistair Ritchie)在AT&T的贝尔实验室开发。其初衷是为了在闲置的PDP-7计算机上开发一个简单的操作系统,以便进行编程和游戏。最初的Unix是用汇编语言编写的,但随后为了更高效的开发和更好的可移植性,里奇和汤普逊用C语言重写了Unix的大部分代码,这奠定了Unix的基础,并促进了C语言的广泛应用。
369 2