![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
no Copy in C#???
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);
}
}
} private void backupToolStripMenuItem_Click(object sender, EventArgs e)But isn't there another way to do it though? ![]() >BstrucT
__________________
>BstrucT |
|
|
|
|
|
#2 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 327
Rep Power: 3
![]() |
Re: no Copy in C#???
This link has a nice list of file functions
__________________
Quote:
|
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
Re: no Copy in C#???
Ooh, I see there is one there.
Thanks kruptof! >BstrucT
__________________
>BstrucT |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copy text of webpage and paste into new email? | jtmark | Java | 14 | Sep 16th, 2006 6:56 PM |
| Help: Template Class' copy constructor | MicahCarrick | C++ | 2 | Jan 23rd, 2006 5:33 AM |
| reverse string copy | codylee270 | C | 23 | Dec 3rd, 2005 8:41 PM |
| copy to clipboard | darkone916 | C++ | 3 | Aug 1st, 2005 4:03 AM |
| how to copy files from one place to another in c | mechmind | C | 15 | Jun 10th, 2005 11:51 PM |