EDN Admin
Well-known member
<pre> try
{
if(Directory::Exists("C:\Users\Test\Sample"))
{
Directory::CreateDirectory("C:\Users\Sample");
array<String^>^files = System::IO:
irectory::GetFiles("C:\Users\Test\Sample");
array<String^>^ dirs = System::IO:
irectory::GetDirectories("C:\Users\Test\Sample");
for each (String^ s in files)
{
String^ fileName = System::IO:
ath::GetFileName(s);
String^ destFile = System::IO:
ath::Combine("C:\Users\Sample", fileName);
System::IO::File::Copy(s, destFile);
}
for each (String^ d in dirs)
{
String^ dname = System::IO:
ath::GetDirectoryName(d);
Directory::CreateDirectory(dname);
array<String^>^dirfiles = System::IO:
irectory::GetFiles(d);
for each (String^ df in dirfiles)
{
String^ fname = System::IO:
ath::GetFileName(df);
String^ dfname = System::IO:
ath::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
{
if(Directory::Exists("C:\Users\Test\Sample"))
{
Directory::CreateDirectory("C:\Users\Sample");
array<String^>^files = System::IO:
![Big grin :D :D](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f600.png)
array<String^>^ dirs = System::IO:
![Big grin :D :D](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f600.png)
for each (String^ s in files)
{
String^ fileName = System::IO:
![Stick out tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
String^ destFile = System::IO:
![Stick out tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
System::IO::File::Copy(s, destFile);
}
for each (String^ d in dirs)
{
String^ dname = System::IO:
![Stick out tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
Directory::CreateDirectory(dname);
array<String^>^dirfiles = System::IO:
![Big grin :D :D](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f600.png)
for each (String^ df in dirfiles)
{
String^ fname = System::IO:
![Stick out tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
String^ dfname = System::IO:
![Stick out tongue :P :P](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
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