I was playing with the recently-released (partial) source code for java (I think1). Or, at least, I wanted to.

But actually finding a file to play with was getting annoying (refer to the picture above), so I created a quick-and-dirty application that basically dumped all files from a source dir (and its children and its grandchildren and its great-grandchildren and so on) into a destination dir.

Recursive directory search:

private void Copy(DirectoryInfo source, string destPath)
{
    foreach (FileInfo file in source.GetFiles())
    {
        try
        {
            CopyFile(file.FullName, destPath);
        }

        catch
        {
            continue;
        }
    }

    foreach (DirectoryInfo child in source.GetDirectories())
    {
        Copy(child, destPath);
    }
}

Copying the file:

private void CopyFile(string sourcePath, string destPath)
{
    string filename = Path.GetFileName(sourcePath);

    string destFilePath = Path.Combine(destPath, filename);

    if (File.Exists(destFilePath))
    {
        filename += "_" + System.DateTime.Now.ToString();

        destFilePath = Path.Combine(destPath, filename);
    }

    File.Copy(sourcePath, destFilePath);
}
  1. I'm, err, sure there's a perfectly good reason for the name "phoneMe_features" (I think the released source code is for phones or something...umm, yeah) but the name brings to mind the not-so-recent debacle with Sony and rootkits...