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 );
}
}
}
}
Replies
Know the answer? Post it — somebody with the same question will find it here.