locked
Copy Help!

    Question

  • I am creating this program which the user can select a source and target folder and it will sync the files in 1 direction.

    Let's say the source is

    E:\Files\Sync

    and the Target is

    C:\My Backups

    Here is my current code:

    public static void OneWaySync()
            {
                int search;
                string folder;
                for (int x = 0; x < sInfo.Length; x++)
                {
                    search = Array.BinarySearch(dInfo, sInfo[x], new SnSArray());

                    if (search < 0)
                    {
                        folder = destination + "\\" + sou;
                        if (Directory.Exists(folder) == false)
                            Directory.CreateDirectory(folder);
                       
                        File.Copy(sInfo[x].FullName, folder + "\\" + sInfo[x].Name , true);
                    }
                    else
                    {
                        if (sInfo[x].LastWriteTime != dInfo[search].LastWriteTime)
                            File.Copy(sInfo[x].FullName, dInfo[search].FullName, true);
                    }
                }

    The current code works but when the file does not exist on destination it copies it.
    But it will copy the folder even if it isnt a sub-folder.

    so if the target is: c:\source
    and destination is e:\sync

    it will copy to e:\sync\source

    I want it to copy the root files to sync, and preserve the subfolders too.

    What am i doing wrong???/
    Monday, May 01, 2006 8:57 AM