Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 16th, 2008, 5:09 AM   #1
BstrucT
Hobbyist Programmer
 
BstrucT's Avatar
 
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 118
Rep Power: 1 BstrucT is on a distinguished road
Send a message via MSN to BstrucT
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);
}
}
}
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
__________________
>BstrucT
BstrucT is offline   Reply With Quote
Old May 16th, 2008, 6:36 AM   #2
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 327
Rep Power: 3 kruptof is on a distinguished road
Re: no Copy in C#???

This link has a nice list of file functions
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old May 16th, 2008, 7:26 AM   #3
BstrucT
Hobbyist Programmer
 
BstrucT's Avatar
 
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 118
Rep Power: 1 BstrucT is on a distinguished road
Send a message via MSN to BstrucT
Re: no Copy in C#???

Ooh, I see there is one there.

Thanks kruptof!

>BstrucT
__________________
>BstrucT
BstrucT is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC