473,379 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 4369
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: 73blazer | last post by:
Hello, I'm writing some C++ code, and I need to be able to find the number of files in a given directory. Is it possible under AIX4.3.3 with C++ 3.6.4? I cannot seem to locate anything of this...
3
by: S. Han | last post by:
I'm using Directory.GetFiles to enumerate files in a directory. The problem is if you have to enumerate all files + subdirectories recursively, it takes too much memory, and it fails. Is there...
11
by: Steve Franks | last post by:
I'm using VS.NET 2005 Beta 2. I have a helper C# class I wrote that I placed in my /App_Code directory. Everything runs fine locally. However when I use the "Copy Web" function to upload the site...
3
by: Karel | last post by:
Hello, I have a VB.NET application where I want to move directories over a network. I tried this with system.io.directory.move, but that doesn't work over different volumes. Has anyone a...
3
by: Phil Galey | last post by:
In VB.NET, is there any way to copy a directory and all its contents to a new location using io.Directory or io.DirectoryInfo etc. without having to import the Scripting.FileSystemObject? ...
23
by: **Developer** | last post by:
Is there an easy way to copies all files in a directory into another directory? What about coping subdirectories too? Thanks in advance for any info
12
by: samoore33 | last post by:
I found a real nice article on how to copy a directory on MSDN. The only problem is that I can not figure out how to get the namespace Microsoft.VisualBasic.MyServices. I wanted to know if anyone...
1
by: dkmarni | last post by:
Hi, I am trying to do this perl script, but not able to complete it successfully. Here is the description what the script has to do.. Accept two and only two command line arguments. Again,...
5
by: pavanponnapalli | last post by:
hi, I have got a list of files in a "list" as follows: foreach(@arr) { copy ("$_", "/home/pavan/tmp") or die "copy failed: $! "; } The path where the files...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.