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

 

相关文章
|
6天前
|
安全 Unix Linux
Veritas NetBackup 11 for Linux & Windows - 领先的企业备份和恢复解决方案
Veritas NetBackup 11 for Linux & Windows - 领先的企业备份和恢复解决方案
20 0
Veritas NetBackup 11 for Linux & Windows - 领先的企业备份和恢复解决方案
|
1天前
|
NoSQL IDE MongoDB
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
40 2
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
10天前
|
自然语言处理 数据库 iOS开发
DBeaver Ultimate Edtion 25.0 Multilingual (macOS, Linux, Windows) - 通用数据库工具
DBeaver Ultimate Edtion 25.0 Multilingual (macOS, Linux, Windows) - 通用数据库工具
63 12
DBeaver Ultimate Edtion 25.0 Multilingual (macOS, Linux, Windows) - 通用数据库工具
|
14天前
|
Linux
Linux 常用文件查看命令
`cat` 命令用于连接文件并打印到标准输出,适用于快速查看和合并文本文件内容。常用示例包括:`cat file1.txt` 查看单个文件,`cat file1.txt file2.txt` 合并多个文件,`cat &gt; filename` 创建新文件,`cat &gt;&gt; filename` 追加内容。`more` 和 `less` 命令用于分页查看文件,`tail` 命令则用于查看文件末尾内容,支持实时追踪日志更新,如 `tail -f file.log`。
41 5
Linux 常用文件查看命令
|
1天前
|
XML 安全 Ubuntu
Nexpose 8.0.0 for Linux & Windows - 漏洞扫描
Nexpose 8.0.0 for Linux & Windows - 漏洞扫描
30 10
|
27天前
|
存储 Linux Shell
Linux|Transfer.sh 轻松实现文件共享
Linux|Transfer.sh 轻松实现文件共享
34 2
Linux|Transfer.sh 轻松实现文件共享
|
1月前
|
人工智能 Linux iOS开发
Burp Suite Professional 2025.2 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
Burp Suite Professional 2025.2 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
71 12
Burp Suite Professional 2025.2 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
|
20天前
|
Linux 网络安全 虚拟化
linux怎么把文件传到docker里面
在现代应用开发中,Docker作为流行的虚拟化工具,广泛应用于微服务架构。文件传输到Docker容器是常见需求。常用方法包括:1) `docker cp`命令直接复制文件;2) 使用`-v`选项挂载宿主机目录,实现数据持久化和实时同步;3) 通过SCP/FTP协议传输文件;4) 在Dockerfile中构建镜像时添加文件。选择合适的方法并确保网络安全是关键。
123 1
|
21天前
|
Linux 虚拟化 Docker
Linux服务器部署docker windows
在当今软件开发中,Docker成为流行的虚拟化技术,支持在Linux服务器上运行Windows容器。流程包括:1) 安装Docker;2) 配置支持Windows容器;3) 获取Windows镜像;4) 运行Windows容器;5) 验证容器状态。通过这些步骤,你可以在Linux环境中顺利部署和管理Windows应用,提高开发和运维效率。
79 1
|
22天前
|
NoSQL IDE MongoDB
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
33 0
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端