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

RT:

[个人小工具]清除SVN控制-LMLPHP

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 == )
{
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();
}
}
}
}
}
05-11 11:36