由于未发布复制文件,我遇到以下代码偶尔无法完成的问题。我想将这个函数包装在using语句中,但不知道如何做到这一点,或者是否有比这更好的解决方案。
感谢。
public static void CopyDirectory (string source, string destination)
{
if (!Directory.Exists (destination))
Directory.CreateDirectory (destination);
string [] sysEntries = Directory.GetFileSystemEntries (source);
foreach (string sysEntry in sysEntries)
{
string fileName = Path.GetFileName (sysEntry);
string targetPath = Path.Combine (destination, fileName);
if (Directory.Exists (sysEntry))
CopyDirectory (sysEntry, targetPath);
else
File.Copy (sysEntry, targetPath, true);
} // foreach (string sysEntry in sysEntries)
}