zoukankan      html  css  js  c++  java
  • 遍历删除文件夹及文件

    1 public void DeleteFileTest(string Spath)
    2 {
    3 if (!Directory.Exists(Spath))
    4 { return; }
    5 string[] fPaths = Directory.GetFiles(Spath);
    6 string[] fsPaths = Directory.GetDirectories(Spath);
    7 try
    8 {
    9 for (int i = 0; i < fPaths.Length; i++)
    10 {
    11 MessageBox.Show(File.GetAttributes(fPaths[i]).ToString());
    12 if (File.GetAttributes(fPaths[i]) == FileAttributes.Normal)
    13 {
    14 File.SetAttributes(fPaths[i], FileAttributes.Normal);
    15 File.Delete(fPaths[i]);
    16 }
    17 else
    18 File.Delete(fPaths[i]);
    19 }
    20 for (int d = 0; d < fsPaths.Length; d++)
    21 {
    22 DirectoryInfo Dinfo = new DirectoryInfo(fsPaths[d]);
    23 if (Dinfo.Attributes != FileAttributes.Normal)
    24 {
    25 this.DeleteFileTest(fsPaths[d]); //递归
    26   Dinfo.Attributes = FileAttributes.Normal;
    27 Dinfo.Delete(true);
    28 }
    29 else
    30 Dinfo.Delete(true);
    31 }
    32 }
    33 catch
    34 {
    35 MessageBox.Show("Error");
    36 return;
    37 }
    38
    39 }
    40
    41  

  • 相关阅读:
    Java绘出pdf实现方法
    Java设置字体颜色
    猜测分箱算法
    获取图片存储到本地
    input(file)异步上传文件
    物流轨迹抓取
    bootstrap 模态框
    从数组中随机选择一个数
    spring cron表达式
    mabtis批量修改
  • 原文地址:https://www.cnblogs.com/wangshuai/p/1635677.html
Copyright © 2011-2022 走看看