• 递归删除一个文件夹下的所有文件c#代码


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;

    namespace TemplateFileDelete
    {
        public partial class DeleteFiles : Form
        {
            int i = 0;
            public DeleteFiles()
            {
                InitializeComponent();
            }

            private void BtOpen_Click(object sender, EventArgs e)
            {
                DealAction(sender, e);
            }

            private void BtOpen2_Click(object sender, EventArgs e)
            {
                DealAction(sender, e);
            }
            public void DealAction(object sender, EventArgs e)
            {
                fbdShow.ShowDialog();
                Button bt = (Button)(sender);
                if (bt.Name == "BtOpen")
                {
                    this.TbPath1.Text = fbdShow.SelectedPath;
                }
                else if (bt.Name == "BtOpen2")
                {
                    this.TbPath2.Text = fbdShow.SelectedPath;
                }

            }
            public void Dirs(string path)
            {
                DirectoryInfo dis = new DirectoryInfo(path);
                FileInfo[] files = dis.GetFiles();
                foreach (FileInfo fi in files)
                {
                    i++;
                    Application.DoEvents();
                    this.label1.Text = i.ToString();
                    try
                    {
                        File.Delete(fi.FullName);
                    }
                    catch (Exception ex)
                    {
                        this.richTextBox1.Text += ex.Message;
                 
                    }
              
                  //  GetSqlFile(fi.FullName, this.textBox1.Text + fi.DirectoryName.Substring(2), fi.FullName.Substring(fi.FullName.LastIndexOf("\\") + 1), 1024, 768);
                }
                if (dis.GetDirectories().Length > 0)
                {
                    for (int i = 0; i < dis.GetDirectories().Length; i++)
                    {
                        Dirs(dis.GetDirectories()[i].FullName);
                    }
                }


            }

            private void BtDelete_Click(object sender, EventArgs e)
            {
                Dirs(this.TbPath1.Text.Trim());
                Dirs(this.TbPath2.Text.Trim());
            }

        }
    }

  • 相关阅读:
    移动端高清、多屏适配方案
    Cookie存中文乱码的问题
    手机网站-前端开发布局技巧汇总
    深入理解javascript中的立即执行函数(function(){…})()
    test
    [PAT] A1013 Battle Over Cities (25分)
    PAT索引
    [PAT] A1012 The Best Rank
    [PAT] A1091 Acute Stroke
    [PAT] A1067 Sort with Swap(0, i)
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835854.html
Copyright © 2020-2023  润新知