problem in copying files and directories

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<pre> try
{
if(Directory::Exists("C:\Users\Test\Sample"))
{
Directory::CreateDirectory("C:\Users\Sample");
array<String^>^files = System::IO::Directory::GetFiles("C:\Users\Test\Sample");
array<String^>^ dirs = System::IO::Directory::GetDirectories("C:\Users\Test\Sample");
for each (String^ s in files)
{
String^ fileName = System::IO::Path::GetFileName(s);
String^ destFile = System::IO::Path::Combine("C:\Users\Sample", fileName);
System::IO::File::Copy(s, destFile);
}
for each (String^ d in dirs)
{
String^ dname = System::IO::Path::GetDirectoryName(d);
Directory::CreateDirectory(dname);
array<String^>^dirfiles = System::IO::Directory::GetFiles(d);
for each (String^ df in dirfiles)
{
String^ fname = System::IO::Path::GetFileName(df);
String^ dfname = System::IO::Path::Combine(d, fname);
System::IO::File::Copy(df, d);
}
}}
}
catch (Exception^ e)
{
MessageBox::Show(e->ToString());
}[/code]
I have written the above code....the purpose is to copy files and directories from one location to another.
what if a directory has files and dirs-> again this one has files and dirs->....like that...can we put this in some kind of loop or some tho solve the problem.
i thought of using system() command to copy files and directories that is xcopy but my requirement is not depend on DOS or any thing...it should be strictly VC++ under VS 2008.
Could anyone help me please.
<
prkac<br/>

View the full article
 
Back
Top