zoukankan      html  css  js  c++  java
  • C#删除文件夹

    这里说三种
     
    1这是最简单的方法
     
            DirectoryInfo di = new DirectoryInfo(string Path);
             di.Delete(true);
      注:path是你要删除的非空目录;
         true:你要删除里面所有的文件,包括文件夹和子文件夹
    2
     /// <summary>
           /// 删除非空文件夹
           /// </summary>
           /// <param name="path">要删除的文件夹目录</param>
            void DeleteDirectory(string path)
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                if (dir.Exists)
                {
                    DirectoryInfo[] childs = dir.GetDirectories();
                    foreach (DirectoryInfo child in childs)
                    {
                        child.Delete(true);
                    }
                    dir.Delete(true);
                }
            }
     
    3 递归方法:(这是删除文件的方法)
    private staticv oid DeleteDirectory(File tmpFile) {
            if (!tmpFile.exists()) {
                 System.out.println("file is not exist!");
                return;
             }
            if (tmpFile.isDirectory()) {
                 File[] fileList = tmpFile.listFiles();
                for (int i =0; i < fileList.length; i++) {
                    if (fileList[i].isDirectory()) {
                         DeleteDirectorys(fileList[i]);s
                     }  
               }
         }
    }
  • 相关阅读:
    VB.NET中lambda的写法
    C#中DllImport用法和路径问题
    SQL*Loader 和 Data Pump
    批处理-函数定义及应用01
    Office 2010 KMS激活原理和案例分享
    Hyper-V架构与VMware ESXi的差异
    Tomcat免安装配置2
    Tomcat免安装配置
    域名解析过程
    内部类访问的局部变量必须加final
  • 原文地址:https://www.cnblogs.com/wggWeb/p/2364521.html
Copyright © 2011-2022 走看看