zoukankan      html  css  js  c++  java
  • [个人小工具]清除SVN控制

        SVN控制说白了就是在.svn文件夹内把项目文件的信息保存,清除SVN控制其实就是把.svn文件夹删除就可以了。但是如果文件夹太多,总不可能一个个文件夹去删除吧,所以写了个遍历文件夹删除的小工具。

        RT:

        

    using System;
    using System.IO;
    using System.Windows.Forms;
    
    namespace RemoveSvnControl
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            /// <summary>
            /// 选择按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btn_select_Click(object sender, EventArgs e)
            {
                var fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    txt_project_path.Text = fbd.SelectedPath;
                }
            }
            /// <summary>
            /// 清除按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btn_clear_Click(object sender, EventArgs e)
            {
                var proPath = txt_project_path.Text.Trim();
                if (string.IsNullOrEmpty(proPath) || !Directory.Exists(proPath))
                {
                    MessageBox.Show(@"此路径不存在!", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
    
                var pro = new DirectoryInfo(proPath);
    
                var sonDirectories = pro.GetDirectories();
    
                if (sonDirectories.Length == 0)
                {
                    MessageBox.Show(@"此路径不存在SVN控制器!", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
    
                try
                {
                    RemoveSvnDirectories(pro);
                    MessageBox.Show(@"移除SVN控制成功!", @"成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
    
            }
            /// <summary>
            /// 移除.svn文件夹
            /// </summary>
            /// <param name="proInfo"></param>
            private void RemoveSvnDirectories(DirectoryInfo proInfo)
            {
                foreach (var directory in proInfo.GetDirectories())
                {
                    if (directory.Name == ".svn")
                    {
                        foreach (var systemInfo in directory.GetFileSystemInfos())
                        {
                            if (systemInfo is DirectoryInfo)
                            {
                                //遍历删除目录
                                DeleteDirectory((DirectoryInfo)systemInfo);
                                systemInfo.Delete();
                            }
                            else
                            {
                                //删除文件
                                systemInfo.Delete();
                            }
                        }
    
                        directory.Delete();
                    }
                }
            }
            /// <summary>
            /// 遍历删除文件夹
            /// </summary>
            /// <param name="directoryInfo"></param>
            private void DeleteDirectory(DirectoryInfo directoryInfo)
            {
                foreach (var info in directoryInfo.GetFileSystemInfos())
                {
                    if (info is DirectoryInfo)
                    {
                        //遍历删除目录
                        DeleteDirectory((DirectoryInfo)info);
                        info.Delete();
                    }
                    else
                    {
                        //删除文件
                        info.Delete();
                    }
                }
            }
        }
    }
  • 相关阅读:
    2020Java面试题及答案,刷这些题,准没错!
    作为一个面试官,我想问问你Redis分布式锁怎么搞?
    你说研究过Spring里面的源码,循环依赖你会么?
    一口气说出 6种 延时队列的实现方案,面试稳稳的
    我可真是醉了,一个SpringBoot居然问了我30个问题
    最强Dubbo面试题,附带超级详细答案
    平安银行Java社招五面面经,目前最全面的,38个面试题以及答案
    Java电子书高清PDF集合免费下载
    Python处理json模块的详细介绍
    用Python写一个“离线语音提示器”来提醒我们别忘记了时间
  • 原文地址:https://www.cnblogs.com/domaple/p/6143748.html
Copyright © 2011-2022 走看看