如果是編輯器不使用運行時的話,直接使用UnityEditor下的API即可
FileUtil.CopyFileOrDirectory
如果是運行時
/// <summary> /// 文件夾拷貝 /// </summary> /// <param name="sourcePath">源路徑</param> /// <param name="destPath">目標路徑</param> private void CopyFolder(string sourcePath, string destPath) { if (Directory.Exists(sourcePath)) { if (!Directory.Exists(destPath)) { try { Directory.CreateDirectory(destPath); } catch (Exception ex) { Debug.LogError("創建失敗"); } } List<string> files = new List<string>(Directory.GetFiles(sourcePath)); files.ForEach(c => { //排除meta文件 if (!c.EndsWith(".meta")) { string destFile = Path.Combine(destPath, Path.GetFileName(c)); File.Copy(c, destFile, true); } }); List<string> folders = new List<string>(Directory.GetDirectories(sourcePath)); folders.ForEach(c => { string destDir = Path.Combine(destPath,Path.GetFileName(c)); CopyFolder(c, destDir); }); } else { Debug.LogError("源目錄不存在"); } }