zoukankan      html  css  js  c++  java
  • 删除目录下的不规则文件

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

    #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;
    }
  • 相关阅读:
    C# 中==和Equal的区别
    3dmath复习随笔
    3dmax学习资料记录
    [官方教程] Unity 5 BLACKSMITH深度分享
    [技术] [插件精选] 炫酷粒子特效(下)
    Unity3D总结:关于射线碰撞
    Unity3D将来时:IL2CPP(上)
    3DMAX 9 角色建模3 uv展开
    php,c# hamsha1
    U3D 的一些基础优化
  • 原文地址:https://www.cnblogs.com/yuandaozhe/p/11458894.html
Copyright © 2011-2022 走看看