private
void
CopyDirectory(
string
srcPath,
string
desPath)
{
string
folderName = srcdir.Substring(srcdir.LastIndexOf(
"\"
)+1);
string
desfolderdir = desPath +
"\"
+ folderName;
if
(desdir.LastIndexOf(
"\"
) == (desPath.Length - 1))
{
desfolderdir = desPath + folderName;
}
string
[] filenames = Directory.GetFileSystemEntries(srcPath);
foreach
(
string
file
in
filenames)
{
if
(Directory.Exists(file))
{
string
currentdir = desfolderdir +
"\"
+ file.Substring(file.LastIndexOf(
"\"
) + 1);
if
(!Directory.Exists(currentdir))
{
Directory.CreateDirectory(currentdir);
}
CopyDirectory(file, desfolderdir);
}
else
{
string
srcfileName = file.Substring(file.LastIndexOf(
"\"
)+1);
srcfileName = desfolderdir +
"\"
+ srcfileName;
if
(!Directory.Exists(desfolderdir))
{
Directory.CreateDirectory(desfolderdir);
}
File.Copy(file, srcfileName);
}
}
}