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

头文件

#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. @Secured(), @PreAuthorize()

    前面简单的提到过这两个注解的区别,那只是从配置以及原理上做的说明,今天,将从使用即代码层面加以说明这两个的使用注意事项! 首先, 若是自己实现用户信息数据库存储的话,需要注意UserDetails的函 ...

  2. IOS开发—数据库的使用

    1.首先封装方法(建一个DataBase类封装) 2.实现DataBase类的方法 3.第一步先建立一个表 4.进行插入.删除.更新 插入的sql语句:@"insert into user ...

  3. Linux下编译java并生成jar包

    下面是WordCount.java类 package com.ll; import java.io.IOException; import java.util.Iterator; import jav ...

  4. nginx 出现 13: Permission denied

    原文地址:http://www.nginx.cn/695.html 前段时间把程序员的wordpress升级到3.5.1,本身如果没有特别的插件,在后台更新就能完成. 更新完成后在后台发布文章,编辑器 ...

  5. java运用Comparator为对象排序

    要排序的类需要实现Comparator接口,重写compare方法: user类及实现接口的内部类: package test; import java.util.Comparator; public ...

  6. FrameWork启动流程

    Android启动过程包含从Linux内核加载到Home应用程序启动的整个过程.整体流程如下: Android是基于Linux内核的系统平台.启动时,首先通过bootloader(系统加载器),加载L ...

  7. GR&R

    ANOVA gauge R&R (or ANOVA gauge repeatability and reproducibility) is a measurement systems anal ...

  8. javascript实现继承的几种方式

    原型链方式实现继承 function SuperType(){ this.property = true; this.colors = ['red','blue','green']; } SuperT ...

  9. Standing on Shouder of Giants

    Zachary_Fan 如何一步一步用DDD设计一个电商网站(二)-- 项目架构 http://www.cnblogs.com/Zachary-Fan/p/6012454.html HTTP 权威指南 ...

  10. socket 发送发送HTTP请求

    socket方式: $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //socket_set_option($socket, SOL_S ...