我想從服務器的共享文件夾複製整個目錄樹到我的本地機器,我發現Best way to copy the entire contents of a directory in C#後,並決定使用,但據我猜DirectoryInfo不支持網絡共享,我怎麼能更改此代碼以使用網絡共享作爲源?從網絡複製整個共享目錄
public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) {
foreach (DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
foreach (FileInfo file in source.GetFiles())
file.CopyTo(Path.Combine(target.FullName, file.Name));
}
編輯
和呼叫
CopyFilesRecursively(new DirectoryInfo ("\\192.168.0.11\Share"), new DirectoryInfo ("D:\Projects\"));
並獲得錯誤信息
Could not find a part of the path 'D:\192.168.0.11\Share'.
非常感謝!
謝謝你的分享!這個爲我工作! – 2018-03-08 09:11:21