471,071 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

directory copy

GS
from the online help, looks like to code step by step to copy content of
directory to another whereas I can use online line code for directory move
or delete.
I am using 2005 express .net 2
I did not any thing(or I did not have the right search term ) for copy
contents of directory to another and replacing /delete all files in the
target directory

Is there an easier way?

Dec 6 '07 #1
4 4234
Hi,

I do not remember any clas sin the framework that does it.
You have two options:
1- Write a recursive method that copy and recreate the struct (using
File.Copy & Directory.CreateDirectory)
2- use xcopy

I would recommend the second option.
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"GS" <gs**********************@msnews.Nomail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
from the online help, looks like to code step by step to copy content of
directory to another whereas I can use online line code for directory move
or delete.
I am using 2005 express .net 2
I did not any thing(or I did not have the right search term ) for copy
contents of directory to another and replacing /delete all files in the
target directory

Is there an easier way?

Dec 6 '07 #2
GS wrote:
from the online help, looks like to code step by step to copy content of
directory to another whereas I can use online line code for directory move
or delete.
I am using 2005 express .net 2
I did not any thing(or I did not have the right search term ) for copy
contents of directory to another and replacing /delete all files in the
target directory

Is there an easier way?
For inspiration:

private void XCopy(string dir1, string dir2)
{
string[] files = Directory.GetFiles(dir1);
foreach (string f in files) {
File.Copy(f, dir2 + f.Substring(dir1.Length), true);
}
string[] dirs = Directory.GetDirectories(dir1);
foreach (string d in dirs) {
XCopy(d, dir2 + d.Substring(dir1.Length));
}
}

Arne
Dec 7 '07 #3
gs
Thank you. I got it working form your inspiration. I tumbled at the for
(string sfile in aDir)
the sfile actually contained the entire file spec including path.
that was not a big deal once found out what is the culprit. took care of by
using indexOfRev and substring

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
GS wrote:
>from the online help, looks like to code step by step to copy content of
directory to another whereas I can use online line code for directory
move
or delete.
I am using 2005 express .net 2
I did not any thing(or I did not have the right search term ) for copy
contents of directory to another and replacing /delete all files in the
target directory

Is there an easier way?

For inspiration:

private void XCopy(string dir1, string dir2)
{
string[] files = Directory.GetFiles(dir1);
foreach (string f in files) {
File.Copy(f, dir2 + f.Substring(dir1.Length), true);
}
string[] dirs = Directory.GetDirectories(dir1);
foreach (string d in dirs) {
XCopy(d, dir2 + d.Substring(dir1.Length));
}
}

Arne

Dec 10 '07 #4
gs
Actually if I copied you code verbatim and modify from there I could have
avoided the trouble.

was not paying attention.

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
GS wrote:
>from the online help, looks like to code step by step to copy content of
directory to another whereas I can use online line code for directory
move
or delete.
I am using 2005 express .net 2
I did not any thing(or I did not have the right search term ) for copy
contents of directory to another and replacing /delete all files in the
target directory

Is there an easier way?

For inspiration:

private void XCopy(string dir1, string dir2)
{
string[] files = Directory.GetFiles(dir1);
foreach (string f in files) {
File.Copy(f, dir2 + f.Substring(dir1.Length), true);
}
string[] dirs = Directory.GetDirectories(dir1);
foreach (string d in dirs) {
XCopy(d, dir2 + d.Substring(dir1.Length));
}
}

Arne

Dec 10 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by 73blazer | last post: by
3 posts views Thread by S. Han | last post: by
3 posts views Thread by Phil Galey | last post: by
12 posts views Thread by samoore33 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.