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();
                    }
                }
            }
        }
    }
  • 相关阅读:
    【Leetcode_easy】720. Longest Word in Dictionary
    【Leetcode_easy】717. 1-bit and 2-bit Characters
    【Leetcode_easy】709. To Lower Case
    【Leetcode_easy】707. Design Linked List
    【Leetcode_easy】706. Design HashMap
    第38课 栈和队列的相互转化
    第7章 网络层协议(4)_IGMP协议
    第7章 网络层协议(3)_ARP协议
    第33课 双向循环链表的实现
    第32课 Linux内核链表剖析
  • 原文地址:https://www.cnblogs.com/domaple/p/6143748.html
Copyright © 2011-2022 走看看