Copy all files from a folder to another folder, recursively

P

pamela fluente

What is the most current (for framework 2.0) and easy way to copy
recursively
all files from folder "Folder1" to folder "Folder2" ?

Is there any simple function in the framework to do that?


-P
 
A

Alex Meleta

Hi pamela,

See there: http://xneuron.wordpress.com/2007/04/12/copy-directory-and-its-content-to-another-directory-in-c/

No easy way, except, probably, Process.Start("xcopy", "c:\old c:\new /O /X
/E /H /K") or Win API functions.

Regards, Alex
[TechBlog] http://devkids.blogspot.com



pf> What is the most current (for framework 2.0) and easy way to copy
pf> recursively
pf> all files from folder "Folder1" to folder "Folder2" ?
pf> Is there any simple function in the framework to do that?
pf>
pf> -P
pf>
 
B

Bob Johnson

One option is to use RoboCopy... it is very powerful, free, and can be
called from batch files. Google RoboCopy to learn more.

-HTH
 
J

Joergen Bech

Google:
http://vbcity.com/forums/topic.asp?tid=19980
http://vbcity.com/forums/faq.asp?fid=15&cat=System
http://www.dotnet247.com/247reference/msgs/45/225766.aspx
http://www.dotnet247.com/247reference/msgs/16/83818.aspx
http://cyrilgupta.com/blog/?p=84
http://www.bubble-media.com/cgi-bin/articles/archives/000026.html

etc etc etc.

All of them suggest writing a recursive method or going
to the Win32 API.

You might want to consider if it should be possible to cancel
the operation, how the function should perform/react when
encountering large files (e.g. DVD ISO images), .lnk "folders",
large collections of files, etc. Perhaps perform the operation
on a separate thread in order not to lock up your interface for
the (unknown) duration of the recursive copy/move.

Regards,

Joergen Bech
 
P

pamela fluente

Hi pamela,

See there:http://xneuron.wordpress.com/2007/04/12/copy-directory-and-its-conten...

No easy way, except, probably, Process.Start("xcopy", "c:\old c:\new /O /X
/E /H /K") or Win API functions.

Regards, Alex
[TechBlog]http://devkids.blogspot.com

pf> What is the most current (for framework 2.0) and easy way to copy
pf> recursively
pf> all files from folder "Folder1" to folder "Folder2" ?
pf> Is there any simple function in the framework to do that?
pf>
pf> -P
pf>

Thanks. Very nice.
 
B

Ben Voigt [C++ MVP]

pamela fluente said:
What is the most current (for framework 2.0) and easy way to copy
recursively
all files from folder "Folder1" to folder "Folder2" ?

Is there any simple function in the framework to do that?

The framework seems to have a hole there. Notice how on this page:
http://msdn2.microsoft.com/en-us/library/system.io.directory(VS.71).aspx

"Copy a directory" has no example. Then click to the 2005 or Orcas version
of the page... "Copy a directory" is gone.

p/invoke to http://msdn2.microsoft.com/en-us/library/ms647743.aspx
 
S

ShaneO

pamela said:
What is the most current (for framework 2.0) and easy way to copy
recursively
all files from folder "Folder1" to folder "Folder2" ?

Is there any simple function in the framework to do that?


-P
I don't know if I'm missing something here, but why not just use the
FileSystem.CopyDirectory(SourceDIR, DestinationDIR) method?

If your reason for wanting it done "Recursively" is because you want to
monitor the progress or trap for errors, then just use some of the
available options provided by this Method.

See "CopyDirectory method" in Help for full details.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
J

Joergen Bech

I don't know if I'm missing something here, but why not just use the
FileSystem.CopyDirectory(SourceDIR, DestinationDIR) method?

If your reason for wanting it done "Recursively" is because you want to
monitor the progress or trap for errors, then just use some of the
available options provided by this Method.

See "CopyDirectory method" in Help for full details.


ShaneO

Kind of a half-baked method. No filter options and
stuck in the VisualBasic namespace rather than the core
framework. No options for recursion depth either.

But perfect answer to the original question.

Regards,

Joergen Bech
 
S

ShaneO

Joergen Bech said:
Kind of a half-baked method.
"half-baked"??? It is a fully mature method, can't see what's
half-baked about it? I can write complex Win32 API calls to accomplish
tasks or purchase 3rd party add-ins just as much as anyone, but choosing
to use, say, the "File.Open" method doesn't make that half-baked in my
opinion! :)
No filter options
None were requested. OP wants to copy "all files"
stuck in the VisualBasic namespace rather than the core
framework.
Only just noticed the OP cross-posted. If a VB question is posted then I
guess a VB solution can be expected to be received.
No options for recursion depth either.
Once again, not requested.
But perfect answer to the original question.
I'm glad you see it as I did.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
P

pamela fluente

I used the recursive code in the xneuron link provided by Alex above.
Is simple, flexible and works perfectly.

Just added a few things like dovents and some messaging and checks. I
recommend it.


-P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top