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可以启动它.
随机推荐
- Android 检测网络连接状态
Android连接网络的时候,并不是每次都能连接到网络,因此在程序启动中需要对网络的状态进行判断,如果没有网络则提醒用户进行设置. 首先,要判断网络状态,需要有相应的权限,下面为权限代码(Androi ...
- 【linux】top命令详解
常用命令 top -d 3 ##每3秒监控一次 [root@TG1704 log]# top top - 14:06:23 up 70 days, 16:44, 2 users, load avera ...
- ettercap ARP dns 欺骗
1.arp 这个简单,太熟了.略过1 2.dns 根据arp欺骗的步骤. 多了个etter.dns文件 找到它:locate etter.dns 进入后添加dns正向解析 启动,选 ...
- 异步I/O编程实例,异步socket
下载地址: http://files.cnblogs.com/badnewfish/RUYEESocket.rar ———————————————————————————————————————— 举 ...
- IntelliJ IDEA中如何设置同时打开多个文件且分行显示?
Window→Editor Tabs→Tabs Placement→Show Tabs in Single Row 取消选中后即可在多行显示 下图为实际显示效果: 还可以自行设置打开文件窗口数(默认 ...
- MIT牛人解说数学体系(转载)
原文网址:http://www.guokr.com/post/442622/ 在过去的一年中,我一直在数学的海洋中游荡,research进展不多,对于数学世界的阅历算是有了一些长进. 为什么要深入数学 ...
- android studio添加三方jar包
jar包放项目的libs目录,然后tools,android,sync project with grade files即可.
- sbt设置
配置中央仓库 vim ~/.sbt/repositories [repositories] local osc: http://maven.oschina.net/content/groups/pub ...
- TCP非阻塞通信
一.SelectableChannel SelectableChannel支持阻塞和非阻塞模式的channel 非阻塞模式下的SelectableChannel,读写不会阻塞 SelectableCh ...
- hdu 5774 Where Amazing Happens
Where Amazing Happens 题意: 让你输出各个队名的出现次数. 题解: 打表题,好坑,相同的没有放在一起,需要认真找,否则容易错. 代码: #include<iostream& ...