复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; using System; public class UteCopyAllFileToKHD { private static string formPath = Application.dataPath + @"ArtsScenes";//原路径 private static string targetPath= @"../../../SourceCodeClientProjectAssetsArtsScenes";//目标路径 ../表示当前项目文件的父路径 private static bool isNull = false; [MenuItem("Tools/拷贝文件夹")] static void init() { Copy(); } private static void Copy() { isNull = false; if(!Directory.Exists(targetPath)) { Log.Error("未找到文件夹"); } CleanDirectory(targetPath); CopyDirectory(formPath, targetPath); if (!isNull) { Debug.Log("Arts\Scenes目录文件导入成功!!"); } } /// <summary> /// 拷贝文件 /// </summary> /// <param name="srcDir">起始文件夹</param> /// <param name="tgtDir">目标文件夹</param> public static void CopyDirectory(string srcDir, string tgtDir) { DirectoryInfo source = new DirectoryInfo(srcDir); DirectoryInfo target = new DirectoryInfo(tgtDir); if (target.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase)) { throw new Exception("父目录不能拷贝到子目录!"); } if (!source.Exists) { return; } if (!target.Exists) { target.Create(); } FileInfo[] files = source.GetFiles(); DirectoryInfo[] dirs = source.GetDirectories(); if(files.Length==0&&dirs.Length==0) { Log.Error("当前项目中Arts\Scenes文件夹为空"); isNull = true; return; } for (int i = 0; i < files.Length; i++) { File.Copy(files[i].FullName, Path.Combine(target.FullName, files[i].Name), true); } for (int j = 0; j < dirs.Length; j++) { CopyDirectory(dirs[j].FullName, Path.Combine(target.FullName, dirs[j].Name)); } } //删除目标文件夹下面所有文件 public static void CleanDirectory( string dir) { foreach (string subdir in Directory.GetDirectories(dir)) { Directory.Delete(subdir, true); } foreach (string subFile in Directory.GetFiles(dir)) { File.Delete(subFile); } } }
最后
以上就是神勇溪流最近收集整理的关于unity3d学习笔记之对文件夹进行拷贝的全部内容,更多相关unity3d学习笔记之对文件夹进行拷贝内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复