• 删除目录下的不规则文件


    之前写代码的时候不严谨 导致产生了很多乱码文件 不太好删除 下面的代码编译后可以进行删除

    #include<stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <stdlib.h>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <arpa/inet.h>
    #include <unistd.h>  
    #include <net/if.h>  
    #include <sys/ioctl.h>  
    #include <sys/types.h>  
    #include <sys/socket.h>  
    #include <fcntl.h>  
    #include <scsi/sg.h>  
    #include <linux/hdreg.h>
    #include <dirent.h>
    #include<sys/time.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <signal.h>
    #include <sys/sysinfo.h>
    #include <string>
    using namespace std;
    void GetRandDir(string dir)
    {
        DIR *dfd;
        struct dirent *dp;
        if ((dfd = opendir(dir.c_str())) == NULL)
        {
            return ;
        }
        while ((dp = readdir(dfd)) != NULL)
        {
            if ('.'==dp->d_name[0])
                continue; /* 璺宠繃褰撳墠鏂囦欢澶瑰拰涓婁竴灞傛枃浠跺す浠ュ強闅愯棌鏂囦欢*/
            string dst=dir+string("/")+string(dp->d_name);
            bool isDir=false;
            {
                struct stat s_buf;
                lstat(dst.c_str(),&s_buf);
                isDir=S_ISDIR(s_buf.st_mode);
            }
            if(!isDir)
            {
                bool flag=false;
                char*p =dp->d_name;
                for(;p[0];++p)
                {
                    if(p[0]>='0'&&p[0]<='9')continue;
                    if(p[0]>='a'&&p[0]<='z')continue;
                    if(p[0]>='A'&&p[0]<='Z')continue;
                    if(p[0]=='-'||p[0]=='+'||p[0]=='.'||p[0]=='=')continue;
                    flag=true;
                }
                if(flag&&strlen(dp->d_name)>1)
                {
                    printf("%s--over
    ",dst.c_str());
                    remove(dst.c_str());
                }
            }
        }
        closedir(dfd);
    }
    int main()
    {
    GetRandDir("/home/player/hms1.0");
    GetRandDir("/home/player/hms");
    return 0;
    }
  • 相关阅读:
    PC上图标显示异常 白色框框处理方案
    判断Javascript变量是否为空 undefined 或者null(附样例)
    MySQL双版本共存解决方案
    跨境电商进口业务的通关模式
    史上最完整跨境电商投资分析报告!
    Fastcgi_Finish_Request 提高页面响应速度
    浏览器工作原理
    thinkphp 命名规范
    git diff ^M的消除
    git简明教程
  • 原文地址:https://www.cnblogs.com/yuandaozhe/p/11458894.html
Copyright © 2020-2023  润新知