Hi Guys
Is there maybe a copy function for the C# language?
I can only find
Directory.Move,
Directory.Delete, etc. but no Copy function?
I know I can do it like this...
public static class CopyUtility
{
public static void CopyAllFiles
(string sourceDirectory, string targetDirectory, bool recursive)
{
if (sourceDirectory == null)
throw new ArgumentNullException(@"C:/Synaps");
if (targetDirectory == null)
throw new ArgumentNullException(@"C:/Backup");
CopyAllFiles(new DirectoryInfo(sourceDirectory), new
DirectoryInfo(targetDirectory), recursive);
}
public static void CopyAllFiles
(DirectoryInfo source, DirectoryInfo target, bool recursive)
{
if (source == null)
throw new ArgumentNullException(@"C:/Synaps");
if (target == null)
throw new ArgumentNullException(@"C:/Backup");
if (!source.Exists)
target.Create();
foreach (FileInfo file in source.GetFiles())
{
file.CopyTo(Path.Combine(target.FullName, file.Name), true);
}
if (!recursive) return;
foreach (DirectoryInfo directory in source.GetDirectories())
{
CopyAllFiles(directory, new DirectoryInfo(Path.Combine
(target.FullName, directory.Name)), recursive);
}
}
} Then just call the below at the let's say, button click event.
private void backupToolStripMenuItem_Click(object sender, EventArgs e)
{
CopyUtility.CopyAllFiles(@"C:/Synaps", @"C:/Backup", true);
}
But isn't there another way to do it though?
>BstrucT