//复制文件夹
public bool CopyDirectory(string srcdir = "", string desdir = "", bool result = false)
{
try
{
string folderName = "";
string[] filenames;
string srcfileName = "";
string mblj = "";
if (!Directory.Exists(desdir))
{
Directory.CreateDirectory(desdir.Trim());
}
folderName = srcdir.Substring(srcdir.LastIndexOf("\\") + 1);
filenames = Directory.GetFileSystemEntries(srcdir);
foreach (string file in filenames)
{
if (Directory.Exists(file))
{
mblj = desdir + "\\" + file.Substring(file.LastIndexOf("\\") + 1);
if (!Directory.Exists(mblj))
{
Directory.CreateDirectory(mblj);
}
CopyDirectory(file, mblj);
}
else
{
srcfileName = file.Substring(file.LastIndexOf("\\") + 1);
mblj = desdir + "\\" + srcfileName;
File.Copy(file, mblj, true);
}
}
return result = true;
}
catch (Exception)
{
return result = false;
}
}