posted on Saturday, May 26, 2007 7:05 PM |

I'm assuming these exist already but I wrote my own. It cleans out the bin, obj, SVN directories so you don't have to. It also removes the resharper directory since no one wants that. If you don't have resharper, i suggest getting it.

XML Code

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="folderPatterns" value=".svn|_Resharper*|bin|obj"/>
    <add key="filePatterns" value="*.resharper|*.resharper.user|*.suo"/>
  </appSettings>
</configuration>

Application

private void button1_Click(object sender, EventArgs e)
{
    if (folderBrowser.ShowDialog() == DialogResult.OK &&
        folderBrowserBackup.ShowDialog() == DialogResult.OK)
    {
        DirectoryInfo di = new DirectoryInfo(folderBrowser.SelectedPath);
        DirectoryInfo backupDir = new DirectoryInfo(
            Path.Combine(folderBrowserBackup.SelectedPath, di.Name));

        textBox1.Text = string.Empty;
        CopyAll(di, backupDir,
            RegexFilePattern(ConfigurationManager.AppSettings[
                "filePatterns"]),
            RegexFilePattern(ConfigurationManager.AppSettings[
                "folderPatterns"]));
    }
}

public static string RegexFilePattern(string input)
{
    return Regex.Replace(input, "\*", "[\w\W]*");
}

public delegate void CopyAllMethod(object state);
public void CopyAll(DirectoryInfo source, DirectoryInfo target,
    string deleteFilePatterns, string deleteFolderPattern)
{
    if (InvokeRequired)
    {
        CopyAllMethod method = delegate {
            CopyAll(source, target, deleteFilePatterns, deleteFolderPattern); };
        BeginInvoke(method, null);
    }
    else
    {
        // Check if the target directory exists, if not, create it.
        if (Directory.Exists(target.FullName) == false)
        {
            Directory.CreateDirectory(target.FullName);
        }

        // Copy each file into it's new directory.
        foreach (FileInfo fi in source.GetFiles())
        {
            Console.WriteLine(@"Copying {0}{1}", target.FullName, fi.Name);
            if (!Regex.IsMatch(
                fi.Name, deleteFilePatterns, RegexOptions.IgnoreCase))
            {
                fi.CopyTo(
                    Path.Combine(target.ToString(), fi.Name), true);
            }
            else
            {
                textBox1.Text += fi.Name + Environment.NewLine;
            }
        }

        // Copy each subdirectory using recursion.
        foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
        {
            if (!Regex.IsMatch(diSourceSubDir.Name, deleteFolderPattern,
                RegexOptions.IgnoreCase))
            {
                DirectoryInfo nextTargetSubDir =
                    target.CreateSubdirectory(diSourceSubDir.Name);
                CopyAll(diSourceSubDir, nextTargetSubDir,
                    deleteFilePatterns, deleteFolderPattern);
            }
            else
            {
                textBox1.Text += diSourceSubDir.Name +
                    Environment.NewLine;
            }
        }
    }
}
Tags [ General ]

Your Comments.

  • # 

    I can't wait to see pictures!! Did you mean Jimmy Kimmel?

    Left by Ian at 5/21/2007 12:05 PM
  • # 

    Of course it was a hard 3 days, but it was also substantial 3 days. I expect your production.
    Good luck.

    Left by Cell at 5/24/2007 3:05 AM
  • # 

    Hay I built almost exactly the same machine but without the PC:
    http://0x0000.org/2007/02/external_combustion_engine_rob_1.html

    Good luck on your project.

    Left by Jonathan Moore at 5/21/2007 8:05 PM
Post Comment
Title *
Name *
Email
Url
Comment *  
Please add 3 and 5 and type the answer here: