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

头文件

#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. Struts2 - Rest(2)

    (上篇:Struts2 - Rest(1)) 6) 加入user-index.jsp到/WEB-INF/content中: <%@ page language="java" ...

  2. SPOJ #500. Turbo Sort

    Sorting is not an out-dated topic. My own in-place qsort got TLE... so, I simply called stl::sort() ...

  3. 利用mtd工具实现嵌入式设备在线升级

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+]   主要思路是:通过web post方式将升级文件交给CGI程序处理,然后通过mtd工具实现设备在线升级. 1.页面部分 & ...

  4. [JavaWebService-axis]-环境搭建

    一.准备 1.下载环境需要的zip包 JDK Eclipse axis(http://axis.apache.org/axis2/java/core/download.html)(axis2-1.7. ...

  5. spark MapOutputTrackerMaster

    最近用了一个RowNumber() over()函数 进行三张4000万数据的关联筛选,建表语句如下: create table CiCustomerPortrait2 as SELECT ROW_N ...

  6. hadoop-spark-hive-hbase配置相关说明

    1. zookeeper 配置 cp app/ochadoop-och3.0.0-SNAPSHOT/zookeeper-3.4.5-cdh5.0.0-beta-2-och3.0.0-SNAPSHOT/ ...

  7. BestCoder Round #84 Bellovin

    Bellovin 题意: 给个中文链接:戳戳戳 题解: 这个题其实就是让你求每一位的最长公共子序列,之后输出就好了,求这个有2个算法,一个是n方,另一个nlogn,所以显然是nlogn的算法,其实这就 ...

  8. ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛

    Lazy Salesgirl Time Limit: 5 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...

  9. jQuery 常见操作实现方式

    一个优秀的 JavaScript 框架,一篇 jQuery 常用方法及函数的文章留存备忘. jQuery 常见操作实现方式 $("标签名") //取html元素 document. ...

  10. Java基础-布局