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();
                    }
                }
            }
        }
    }
  • 相关阅读:
    SpringMVC整合redis(Spring Data Redis)
    maven——pom.xml
    腾讯云Nginx配置HTTPS
    LNMP运行环境搭建
    Mac——homebrew安装PHP环境
    Yii2之路——安装配置
    Linux之路——FFmpeg安装
    PHP之路——geohash查找附近的人
    PHPStorm对laravel代码自动提示
    shell命令总结
  • 原文地址:https://www.cnblogs.com/domaple/p/6143748.html
Copyright © 2011-2022 走看看