zoukankan      html  css  js  c++  java
  • 删除多级非空目录

    void DeleteDir(CString str)
    {
     CFileFind finder;      //文件查找类
     CString strdel,strdir; //strdir:要删除的目录,strdel:要删除的文件
     strdir=str+"//*.*";    //删除文件夹,先要清空文件夹,加上路径,注意加"//"
     BOOL b_finded=(BOOL)finder.FindFile(strdir);
     while(b_finded)
     {
      b_finded=(BOOL)finder.FindNextFile();
      if (finder.IsDots())  continue;//找到的是当前目录或上级目录则跳过
      strdel=finder.GetFileName(); //获取找到的文件名
      if(finder.IsDirectory())   //如果是文件夹
      {
       strdel=str + "//" + strdel;//加上路径,注意加"//"
       DeleteDir(sock,strdel); //递归删除文件夹
      }
      else //不是文件夹
      {
       strdel=str + "//" + strdel;
       if(finder.IsReadOnly())//清除只读属性
       {   
        SetFileAttributes(strdel,GetFileAttributes(strdel)&(~FILE_ATTRIBUTE_READONLY));
       }
       DeleteFile(strdel); //删除文件(API)
      }
     }
     finder.Close();
     RemoveDirectory(str); //删除文件夹(API)
    }
  • 相关阅读:
    pycharm过期后,修改hosts文件?
    三种格式化方式
    virtualenv安装及使用
    二分查找以及单例模式
    目录总览
    SQLAlchemy
    Redis
    linux 安装虚拟机
    shell基本命令
    Linux 命令大全
  • 原文地址:https://www.cnblogs.com/tyjsjl/p/2156056.html
Copyright © 2011-2022 走看看