0
Answer

c# copy folders smal help

george

george

16y
2.3k
1

Hi guys! I’m beginner with C# and I experiment with the language! Please can someone help me with an example form to copy folders and its contents with progress bar , overwrite folder-file selection,  and cancel button?

 

I have found in internet this code and il tested it works but no progress bar and no cancel 

 

 

using System;
using System.IO;
 
namespace CSharp411
{
    class Program
    {
        static void Main( string[] args )
        {
            CopyFolder( @"C:\temp\test", @"C:\temp\out" );
            Console.ReadLine();
        }
        static public void CopyFolder( string sourceFolder, string destFolder )
        {
            if (!Directory.Exists( destFolder ))
                Directory.CreateDirectory( destFolder );
            string[] files = Directory.GetFiles( sourceFolder );
            foreach (string file in files)
            {
                string name = Path.GetFileName( file );
                string dest = Path.Combine( destFolder, name );
                File.Copy( file, dest );
            }
            string[] folders = Directory.GetDirectories( sourceFolder );
            foreach (string folder in folders)
            {
                string name = Path.GetFileName( folder );
                string dest = Path.Combine( destFolder, name );
                CopyFolder( folder, dest );
            }
        }
    }
}