bat 放program files下找不到指定文件_C#删除指定目录空文件夹(源码)

Lete乐特自制删除指定目录空文件夹工具(C# - .NET Framework4.5)

卸载软件的时候有些软件只删除程序,并不删除文件夹 以前不会编程,网上找教程大部分都是bat文件的教程 (放到想要删除的目录下运行,但这只能删除这个目录下的空目录,不能删除这个目录下空目录的子目录) 为了方便自己就动手写了一个

cf473c741120d4fe4d8d2680a28c28b1.png

Main.cs

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

namespace Delete
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        // 浏览
        private void btnLL_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog f = new FolderBrowserDialog();
            if (f.ShowDialog() == DialogResult.OK)
            {
                String DirPath = f.SelectedPath;
                this.txtPath.Text = DirPath;//G:新建文件夹
            }
        }

        // 开始
        private void btnDelete_Click(object sender, EventArgs e)
        {
            // 获取路径
            string str = txtPath.Text;
            str.Replace("", "/");
            if (str.Equals(""))
            {
                MessageBox.Show("路径不能为空!", "提示");
            }
            else if (str.Equals("Q:") || str.Equals("W:") || str.Equals("E:") || str.Equals("R:") || str.Equals("T:") || str.Equals("Y:") || str.Equals("U:") || str.Equals("I:") || str.Equals("O:") || str.Equals("P:") || str.Equals("A:") || str.Equals("S:") || str.Equals("D:") || str.Equals("G:") || str.Equals("H:") || str.Equals("J:") || str.Equals("K:") || str.Equals("L:") || str.Equals("Z:") || str.Equals("X:") || str.Equals("C:") || str.Equals("C:") || str.Equals("V:") || str.Equals("B:") || str.Equals("N:") || str.Equals("M:"))
            {
                MessageBox.Show("路径不能为盘符!", "提示");
            }
            else
            {
                getPath(str);
            }
        }


        static List<string> list = new List<string>();//定义list变量
        public List<string> getPath(string path)
        {
            // 获取子目录
            DirectoryInfo dir = new DirectoryInfo(path);
            FileInfo[] fil = dir.GetFiles();
            DirectoryInfo[] dii = dir.GetDirectories();
            foreach (FileInfo f in fil)
            {
                list.Add(f.FullName);//添加文件的路径到列表
            }
            //获取子文件夹内的文件列表,递归遍历
            foreach (DirectoryInfo d in dii)
            {
                getPath(d.FullName);
                list.Add(d.FullName);//添加文件夹的路径到列表
            }

            // 删除空目录
            /// 删除掉空文件夹
            /// 所有没有子“文件系统”的都将被删除
            DirectoryInfo[] subdirs = dir.GetDirectories("*.*", SearchOption.AllDirectories);
            foreach (DirectoryInfo subdir in subdirs)
            {
                FileSystemInfo[] subFiles = subdir.GetFileSystemInfos();
                if (subFiles.Count() == 0)
                {
                    subdir.Delete();
                }
            }

            return list;
        }



        // 文本框
        private void txtPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog f = new FolderBrowserDialog();
            if (f.ShowDialog() == DialogResult.OK)
            {
                String DirPath = f.SelectedPath;
                this.txtPath.Text = DirPath;//G:新建文件夹
            }
        }

        // 乐特 s' Blog
        private void lblLete_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://lete114.github.io/");
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Delete
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());
        }
    }
}

下载地址

这里顺便推荐个云盘曲奇云盘https://quqi.com用了有几个月了还不错
同样和百度云一样送2T空间,晚了可能就没有了,关键是不限速

曲奇云盘:https://quqi.gblhgk.com/s/47889/zZ9iap4ZScYMyf5p

Github:https://github.com/lete114/Delete.Tools

Gitee:乐特/Delete.Tools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值