vc 递归删除非空文件夹
我觉得这是一个非常不错的递归例子
头文件
#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 递归删除非空文件夹的更多相关文章
- NodeJs递归删除非空文件夹
此篇博文由于第一次使用fs.unlink()删除文件夹时报“Error: EPERM: operation not permitted, unlink”错误而写,这是因为fs.unlink()只能删除 ...
- 如何使用python移除/删除非空文件夹?
移除/删除非空文件夹/目录的最有效方法是什么? 1.标准库参考:shutil.rmtree. 根据设计,rmtree在包含只读文件的文件夹树上失败.如果要删除文件夹,不管它是否包含只读文件,请使用 i ...
- 【转】 python 删除非空文件夹
转自:https://blog.csdn.net/xiaodongxiexie/article/details/77155864 一般删除文件时使用os库,然后利用os.remove(path)即可完 ...
- windows C++删除非空文件夹
//add by zhuxy 递归删除文件夹 BOOL myDeleteDirectory(CString directory_path) //删除一个文件夹下的所有内容 { BOOL ret=TRU ...
- python 删除非空文件夹
import os import shutil os.remove(path) #删除文件 os.removedirs(path) #删除空文件夹 shutil.rmtree(path) #递归删除文 ...
- C 实现删除非空文件夹
/* 文件名: rd.c ---------------------------------------------------- c中提供的对文件夹操作的函数,只能对空文件夹进行 删除,这使很多 ...
- mac 下删除非空文件夹
Linux中rmdir命令是用来删除空的目录.使用方式: rmdir [-p] dirName 参数: -p 是当子目录被删除后使它也成为空目录的话,则顺便一并删除. 举例说明:rmdir folde ...
- QT删除非空文件夹
int choose; choose = QMessageBox::warning(NULL,"warning","确定删除该文件?",QMessageBox: ...
- shell命令rm删除非空文件夹
rm -rf dirName CentOS的自带的资源管理器叫nautilus,在命令行里输入nautilus可以启动它.
随机推荐
- IOS开发-UI基础-视图
//------------------------------UIWindow--------------------------// 1.UIWindow:是 UIView 的子类,用于管理.协调 ...
- 【linux】cut
vim test id name age score 101 paul 18 100 102 suan 11 99 103 peter 18 98 [root@andon ~]# cut -f 2 t ...
- php xdebug xampp eclipse
Eclipse配置 一:配置workspace 打开Eclipse for PHP Developers,需要设置workspace,这个必须设置到C:\xampp\htdocs目录,否则待会无法进行 ...
- win8以管理员身份安装软件
win8以管理员身份安装软件 msiexec /package
- 【solr】solr5.0整合中文分词器
1.solr自带的分词器远远满足不了中文分词的需求,经查使用最多的分词器是solr是mmseg4j分词器,具体整合大家可以参考 https://github.com/zhuomingliang/mms ...
- 一个Oracle触发器的示例
CREATE OR REPLACE TRIGGER WoStateChange AFTER UPDATE on csdbuser.T_PD_WorkOrder for each row declare ...
- PLSQL_性能优化工具系列10_Automatic Database Diagnostic Monitor - ADDM
2014-09-06 Created By BaoXinjian
- 《挑战程序设计竞赛》 4.1.1 矩阵 P286
想写几篇挑战的感悟,也有助于自己理解这本书.但这上面大多贴的是书上的代码,主要是为了用的时候后直接复制就好了,这样就很方便了,就相当于黑盒模板了. 1.线性方程组 /** \brief 高斯消元法 * ...
- HDU 2717 Catch That Cow(BFS)
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
- http请求的referer属性
HTTP Referer是header的一部分,当浏览器向web服务器发送请求的时候,一般会带上Referer,告诉服务器我是从哪个页面链接过来的,服务器籍此可以获得一些信息用于处理.比如从我主页上链 ...