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();
                    }
                }
            }
        }
    }
  • 相关阅读:
    [Javascript] twitterbootstrap: 解决2.1版本中modal加载远程内容时,只加载一次的问题
    向大型网站学习SEO优化之道
    [Yii Framework] 使用Yii Framework开发微信公众平台
    [jQuery] ajax跨域处理方式
    [jQuery] form提交到iframe之后,获取iframe里面内容
    [Ubuntu] fatal: recursion detected in die handler
    [Yii Framework] Yii如何实现前后台的session分离
    [ubuntu] ubuntu13.04 64bit,安装FastDFS4.06过程遇到的问题和解决方案
    [转] 怎样在Ubuntu上安装Git服务器
    [ubuntu] ubuntu13.04切换桌面/工作区的方法
  • 原文地址:https://www.cnblogs.com/domaple/p/6143748.html
Copyright © 2011-2022 走看看