Unity获取指定资源目录下的所有文件


使用前需要引入System.IO;这个命名空间

 1 public void GetFiles()
 2 {
 3     //路径 
 4     //string path = string.Format("{0}", Application.streamingAssetsPath);
 5     string path = string.Format("{0}", @"D:\SHU170221U3D-09\Lesson14\Assets\StreamingAssets");
 6 
 7     //获取指定路径下面的所有资源文件  
 8     if (Directory.Exists(path))
 9     {
10         DirectoryInfo direction = new DirectoryInfo(path);
11         FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
12 
13         Debug.Log(files.Length);
14 
15         for (int i = 0; i < files.Length; i++)
16         {
17             if (files[i].Name.EndsWith(".meta"))
18             {
19                 continue;
20             }
21             Debug.Log("Name:" + files[i].Name);
22             Debug.Log("FullName:" + files[i].FullName);
23             Debug.Log("DirectoryName:" + files[i].DirectoryName);
24         }
25     }
26 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM