#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\n", str.c_str());

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

_findclose(h);
}

c/c++常用代码--清空目录的更多相关文章

  1. Android 常用代码大集合 [转]

    [Android]调用字符串资源的几种方法   字符串资源的定义 文件路径:res/values/strings.xml 字符串资源定义示例: <?xml version="1.0&q ...

  2. PyTorch常用代码段整理合集

    PyTorch常用代码段整理合集 转自:知乎 作者:张皓 众所周知,程序猿在写代码时通常会在网上搜索大量资料,其中大部分是代码段.然而,这项工作常常令人心累身疲,耗费大量时间.所以,今天小编转载了知乎 ...

  3. 转--Android实用的代码片段 常用代码总结

    这篇文章主要介绍了Android实用的代码片段 常用代码总结,需要的朋友可以参考下     1:查看是否有存储卡插入 复制代码 代码如下: String status=Environment.getE ...

  4. 【Django】基于Django架构网站代码的目录结构

     经典的Django项目源码目录结构 Django在一个项目的目录结构划分方面缺乏必要的规范.在Django的官方文档中并没有给出大型项目的代码建议目录结构,网上的文章也是根据项目的不同结构也有适当的 ...

  5. NSIS常用代码整理

    原文 NSIS常用代码整理 这是一些常用的NSIS代码,少轻狂特意整理出来,方便大家随时查看使用.不定期更新哦~~~ 1 ;获取操作系统盘符 2 ReadEnvStr $R0 SYSTEMDRIVE ...

  6. Lambda表达式常用代码示例

    Lambda表达式常用代码示例 2017-10-24 目录 1 Lambda表达式是什么2 Lambda表达式语法3 函数式接口是什么  3.1 常用函数式接口4 Lambdas和Streams结合使 ...

  7. lua中清空目录和递归创建目录

    lua中的 lfs.mkdir lfs.rmdir只能针对单个目录,且lfs.rmdir不能清空文件夹 于是我想到了使用os.execute 递归创建目录如下os.execute("mkdi ...

  8. GCD 常用代码

    GCD 常用代码 体验代码 异步执行任务 - (void)gcdDemo1 { // 1. 全局队列 dispatch_queue_t q = dispatch_get_global_queue(0, ...

  9. 刀哥多线程之03GCD 常用代码

    GCD 常用代码 体验代码 异步执行任务 - (void)gcdDemo1 { // 1. 全局队列 dispatch_queue_t q = dispatch_get_global_queue(0, ...

随机推荐

  1. Android渠道汇总

    序号 渠道名  渠道说明 特殊渠道   1 googleplay  google市场 2 umeng  自动更新 3 office_web  官方网络 4 office_qrcode 官方二维码 硬件 ...

  2. C++之算法题模板

    main.cpp: #include <iostream>#include <vector>#include <cstring>#include <cstdi ...

  3. CSS盒模型简单用法

    1.盒模型 margin:外边距: margin-top /margin-right/margin-bottom/margin-left; 或者 margin:top right bottomleft ...

  4. Jquery实现循环删除Reaper某一行

    一.实现的效果图:(点击删除图标,juery实现删除整行) 二.MVC开发模式 SQLServer层 #region 删除 /// <summary> /// 根据自动编号删除快递线路信息 ...

  5. Jquery操作radio,checkbox,select表单操作实现代码

    一 .Select jQuery获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); / ...

  6. OpenGl从零开始之坐标变换

    http://www.tuicool.com/articles/uiayYrI OpenGL学习脚印: 坐标变换过程(vertex transformation) http://blog.csdn.n ...

  7. Excel VBA 快捷键 代码

    一. 在ThisWorkbook中 Private Sub Workbook_Open() '%对应alt键 宏不能加() Application.OnKey "%q", &quo ...

  8. 20150528—html使用Jquery遍历text文本框的非空验证

    <script src="jquery-1.7.2.min.js" type="text/javascript"></script> & ...

  9. GPRS组网的几种方案【来自网络】

    GPRS组网的几种方案:1) 方案一:中心采用ADSL等INTELNET公网连接,采用公网固定IP或者公网动态IP+DNS解析服务.此种方案向先INTERNET运营商申请ADSL等宽带业务.     ...

  10. (转)LR监控Linux系统性能计数器详解

    从LR里面add measurement,填写linux机器的IP,出现所有unix/linux的计数器,包括cpu的,mem的,disk,network的.这里介绍几个常用的: (对于如何监控Lin ...