zoukankan      html  css  js  c++  java
  • asp.net 文件夹和文件的创建、删除

    View Code
     1     /// <summary>   
     2     /// 用递归方法删除文件夹目录及文件   
     3     /// </summary>   
     4     /// <param name="dir">带文件夹名的路径</param>    
     5     public void DeleteFolder(string dir)
     6     {
     7         if (Directory.Exists(dir)) //如果存在这个文件夹删除之    
     8         {
     9             foreach (string d in Directory.GetFileSystemEntries(dir))
    10             {
    11                 if (File.Exists(d))
    12                     File.Delete(d); //直接删除其中的文件                           
    13                 else
    14                     DeleteFolder(d); //递归删除子文件夹    
    15             }
    16             Directory.Delete(dir, true); //删除已空文件夹                    
    17         }
    18     }
    19 
    20     /// <summary>   
    21     /// 创建文件夹   
    22     /// </summary>   
    23     /// <param name="Path"></param>   
    24     public void FolderCreate(string Path)
    25     {
    26         // 判断目标目录是否存在如果不存在则新建之   
    27         if (!Directory.Exists(Path))
    28             Directory.CreateDirectory(Path);
    29     }

     
    确保您具有足够的权限 对路径 的访问被拒绝

    删除权限设置:
    在web.config中的<system.web>下加入<identity impersonate="true"/>

    删除文件夹下的文件

        protected void ss232_Click(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo path = new System.IO.DirectoryInfo("C:\\fingerPrint\\ss");
            deletefile(path);
        }

        private void deletefile(System.IO.DirectoryInfo path)
        {
            foreach (System.IO.DirectoryInfo d in path.GetDirectories())
            {
                deletefile(d);
            }
            foreach (System.IO.FileInfo f in path.GetFiles())
            {
                f.Delete();
            }
        } 


     

  • 相关阅读:
    strcat strcpy 使用出现的问题汇总
    MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
    nginx 设置反响代理实现nginx集群
    js 去掉字符串最后一个字符
    二维数组 获取某键值集合
    oracle 序列
    递归数据查询
    oracle 递归查询
    jQuery EasyUI API 中文文档
    SecureCRT使用的技巧 键盘修改
  • 原文地址:https://www.cnblogs.com/bdf216/p/2642691.html
Copyright © 2011-2022 走看看