我觉得这是一个非常不错的递归例子

头文件

#pragma once

#include <atlstr.h>

#include <io.h>

#include <string>

#include <iostream>

#include <windows.h>

using namespace std;

BOOL Deleteall(CString path)

{

 long handle = -1;   //用于查找的句柄

 CString strFilePath = "";

 CString strLog = "";

 strFilePath = strPath + "*.*";

struct _finddata_t fileinfo;   //文件信息的结构体

handle=_findfirst(strFilePath,&fileinfo);

 if (handle != -1)

 {

  do

  {

   int isSubDir = fileinfo.attrib & _A_SUBDIR;

   if(isSubDir)                                   //如果是文件夹

   {

    //CString FileName = fileinfo.name;

    string strFileName(fileinfo.name );

    if(strFileName.compare(".") != 0 && strFileName.compare("..") != 0)

    {

     CString NewPath = strPath + strFileName.c_str() + "\\" ;

     DeleteAllFile(NewPath);         //递归

    }

   }

   else

   {

    CString str1(strPath);

    string str2(fileinfo.name );

    CString strfilepath = str1 + str2.c_str();

    if(!DeleteFile(strfilepath))

    {

     strLog.Format("delete %s is failed,errorCode :%d\n", str2, GetLastError());

     cout<<strLog;

    }

   }

  }while(_findnext(handle, &fileinfo) != -1); // 遍历此目录下所有文件找配置文件??

  _findclose(handle);

if(!RemoveDirectory(strPath))

  {

   strLog.Format("delete %s is failed errorCode :%d\n", strPath, GetLastError());

   cout<<strLog;

   return FALSE;

  }

  else

  {

   strLog.Format("delete %s is succeed\n", strPath);

   cout<<strLog;

  }

 }

 return 0;

}

main文件

void main()

{

CString path = "D:\\work\\" ;

if(DeleteFiles(path))

   cout<<"delete succeed"<<endl;

else

   cout<<"delete fail"<<endl;

}

vc 递归删除非空文件夹的更多相关文章

  1. NodeJs递归删除非空文件夹

    此篇博文由于第一次使用fs.unlink()删除文件夹时报“Error: EPERM: operation not permitted, unlink”错误而写,这是因为fs.unlink()只能删除 ...

  2. 如何使用python移除/删除非空文件夹?

    移除/删除非空文件夹/目录的最有效方法是什么? 1.标准库参考:shutil.rmtree. 根据设计,rmtree在包含只读文件的文件夹树上失败.如果要删除文件夹,不管它是否包含只读文件,请使用 i ...

  3. 【转】 python 删除非空文件夹

    转自:https://blog.csdn.net/xiaodongxiexie/article/details/77155864 一般删除文件时使用os库,然后利用os.remove(path)即可完 ...

  4. windows C++删除非空文件夹

    //add by zhuxy 递归删除文件夹 BOOL myDeleteDirectory(CString directory_path) //删除一个文件夹下的所有内容 { BOOL ret=TRU ...

  5. python 删除非空文件夹

    import os import shutil os.remove(path) #删除文件 os.removedirs(path) #删除空文件夹 shutil.rmtree(path) #递归删除文 ...

  6. C 实现删除非空文件夹

    /* 文件名:   rd.c ---------------------------------------------------- c中提供的对文件夹操作的函数,只能对空文件夹进行 删除,这使很多 ...

  7. mac 下删除非空文件夹

    Linux中rmdir命令是用来删除空的目录.使用方式: rmdir [-p] dirName 参数: -p 是当子目录被删除后使它也成为空目录的话,则顺便一并删除. 举例说明:rmdir folde ...

  8. QT删除非空文件夹

    int choose; choose = QMessageBox::warning(NULL,"warning","确定删除该文件?",QMessageBox: ...

  9. shell命令rm删除非空文件夹

    rm -rf dirName CentOS的自带的资源管理器叫nautilus,在命令行里输入nautilus可以启动它.

随机推荐

  1. jQuery.KinSlideshow焦点图轮换

    兼容IE6/IE7/IE8/IE9,FireFox,Chrome*,Opera的 jQuery. KinSlideshow幻灯片插件,功能很多 ,基本能满足你在网页上使用幻灯片(焦点图)效果. 演示网 ...

  2. 安卓 NEXUS6 修改分辨率,density

    NEXUS6原density数值: 2k屏 560 每一步: 使用RE文件管理器,编辑system/build.prop.将“ro.sif.lcd_density=”的参数改写成为需要修改的数值,保存 ...

  3. 剑指offer系列22--二叉树中和为某一值的路径

    22[题目]输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径. * 路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径 * [思路]只要从根结点到叶结点一条一条遍 ...

  4. Func系列3:自定义模块

    简介 Func自带的模块已经非常丰富,但在日常系统运维当中,尤其是面对大规模的服务器集群.不同类别的业务平台,次是Func自带的模块或许已经不能满足我们的需求,所以有必要通过自定义模块来填补这块的不足 ...

  5. 216. Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  6. Patial修饰符

    C#中新建一个Windows Form时,后台代码都会自动添加如下代码: public partial class Form1 : Form { public Form1() { Initialize ...

  7. JavaScript中Call()以及Apply()的应用

    apply()和call()的真正用武之地是能够扩充函数赖以运行的作用域 三点说明: 1.每个函数都包含两个非继承而来的方法:apply()和call(). 2.他们的用途相同,都是在特定的作用域中调 ...

  8. try catch 怎么写?

    除非必要,否则不在底层写try catch. 比如说,需要在catch里做一些处理,然后再抛出,一般不建议使用try catch掩盖程序出现的异常. try {     BuildQueryComma ...

  9. Codeforces Round #367 (Div. 2) Hard problem

    Hard problem 题意: 有n个字符串,对第i个字符串进行反转操作代价为ci. 要使n个字符串按照字典序从小到大排列,最小的代价是多少. 题解: 反转就是reverse操作,比如说45873反 ...

  10. BestCoder Round #84 Aaronson

    Aaronson 题意: 给个中文链接:戳戳戳 题解: 这题一看给的公式就是二进制,之后马上就能想到当m大于等于二进制的位数时,输出n的二进制的1的个数就好了.之后就是m小于二进制的位数时,只要加上2 ...