zoukankan      html  css  js  c++  java
  • c/c++常用代码--清空目录

    #pragma once

    #include <io.h>
    #include <stdio.h>
    #include <string>
    #include <direct.h>


    static void clean_dir(const char* szDir)
    {
        if (szDir == NULL || strlen(szDir) == 0)
            return;

        std::string strDir = szDir;

        char c = strDir[strDir.length() - 1];
        if (c != '/' && c != '\')
            strDir += '/';

        struct _finddata_t fd;
        long h=_findfirst((strDir + "*.*").c_str(), &fd);
        if (h == -1)
        {
            return ;
        }

        do
        {
            if (strcmp(fd.name, ".") == 0
                || strcmp(fd.name, "..") == 0)
                continue;

            if (fd.attrib & (_A_SYSTEM | _A_HIDDEN))
                continue;

            if (fd.attrib & _A_SUBDIR)
            {
                std::string str = strDir + fd.name + "/";
                clean_dir(str.c_str());
                rmdir(str.c_str());
                continue;
            }
            
            std::string str = strDir + fd.name;
            printf("%s ", str.c_str());        

            remove(str.c_str());
        }
        while (_findnext(h, &fd)==0);

        _findclose(h);
    }

  • 相关阅读:
    mysql常见的优化方法
    Mac 怎么通过自带终端连接linux服务器
    基于 appium 的 UI 自动化测试
    sourcetree在mac上的使用
    mac下git安装和使用
    mac 上更改环境变量
    Mac环境下svn的使用
    jira常用配置
    influxDB基本操作
    Collectd 和 InfluxDB 的部署和使用
  • 原文地址:https://www.cnblogs.com/vc60er/p/3929934.html
Copyright © 2011-2022 走看看