Answers
Mar 17, 2009 - 08:58 AM
....
System.IO.Directory.Move(sourcepath, destpath)
....
string[] files = System.IO.Directory.GetFiles(path)
foreach(string path in files)
{
System.IO.File.Copy(path,destinationpath)
}
string[] dirs = System.IO.Directory.GetDirectories()
foreach(string dir in dirs)
{
destdir = destinationpath + "\\" + dir;
System.IO.Directory.CreateDirectory(destdir);
}
Somathing like this.
Mar 17, 2009 - 09:10 AM
I understand the principle of what you posted, but your code doesn't look completely tested. I mean how does it copy files or folders within folders. I think it lacks recursiveness.
But I did find a method that does what I wanted and looks similar to yours:
http://xneuron.wordpress.com/2007/04/...
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
// Check if the target directory exists, if not, create it.
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
// Copy each file into it’s new directory.
foreach (FileInfo fi in source.GetFiles())
{
Console.WriteLine(@”Copying {0}\{1}”, target.FullName, fi.Name);
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
}
// Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir =
target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
Add New Comment