When I copy a file I get The process cannot access the file "..." because it is being used by another process
<p>I know this is a really easy one for you guys. I am new at this and I know there is probly a program that does this but I want to learn.</p>

<p>My program will copy files from one location to another, depending on the age of the file. However when the file going to get copied I get the error. here are my three classes.</p>

<pre><code>//find.cs

using System;
using System.IO;
using System.Collections;

namespace findold
{
    class find
    {
        static void Main(string[] args)
        {
            Console.Write("Please select option to use: [C]opy, [M]ove, [D]elete : ");
            string type = Convert.ToString(Console.ReadLine());

            Console.Write("What is the source path: ");
            DirectoryInfo source = new DirectoryInfo(Console.ReadLine());

            Console.Write("What is the destination path: ");
            string destination = Console.ReadLine();

            Console.Write("Files of what age do you want manage: ");
            Int32 months  = Convert.ToInt32(Console.ReadLine());


            string rootPath = Convert.ToString(source.Parent);
            string newDest = Path.Combine(destination, rootPath);

            if (type.ToUpper() == "C")
                copy.CopyFolder(Convert.ToString(source), newDest, type, months);

            //if (type.ToUpper() == "M")
              //  move.MoveFolder(source, newDest, type, months);

            Console.WriteLine("All Done!");
            Console.ReadLine();

        } // end static main
    } // End find Class
} // End findold namespace

//copy.cs

using System;
using System.IO;

class copy
{
    static public void CopyFolder(string sourceFolder, string destFolder, string type, Int32 past)
    {

        string[] files = Directory.GetFiles(sourceFolder);

        foreach (string f in files)
        {
            string name = f;
            string dest = Path.Combine(destFolder, name);

            if (compare.timestamp(f, past) == true)
            {
                if (!Directory.Exists(destFolder))
                    Directory.CreateDirectory(destFolder);

                File.Copy(f, dest, true);
            }

            Console.WriteLine(f);
        }

        string[] folders = Directory.GetDirectories( sourceFolder);

        foreach (string folder in folders)
        {
            string name = Path.GetFileName(folder);
            string dest = Path.Combine(Convert.ToString(destFolder), name);

            CopyFolder(folder, dest, type, past);
        }
    } // End CopyFolder method

}

//compare.cs

using System;
using System.IO;

class compare
{
    public static Boolean timestamp(string file, Int32 back)
    {
            FileInfo fi = new FileInfo(file);

            if (fi.LastWriteTime &lt; DateTime.Now.AddMonths(back))
            {
                Console.WriteLine("{0} was written on {1}", fi.FullName, fi.LastWriteTime);
                return true;
            }

            return false;
    }

}
</code></pre>

<p>Each one of these are seperate files. I am not sure why it is not working correctly. It bombs after it comes back from the compare and I ask it to perform the copy. Thanks for your help</p>
