Unity遍历所选文件夹中包含某后缀名的文件路径
2014-12-24 15:18
531 查看
//遍历所选文件夹,查找该文件夹以及子文件夹中 后缀为 .prefab的文件路径 using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEditor; using System.IO; public class CameraMove : MonoBehaviour { // 在菜单来创建 选项 , 点击该选项执行搜索代码 [MenuItem("Tools/遍历项目所有文件夹")] static void CheckSceneSetting() { List<string> dirs = new List<string>(); GetDirs(Application.dataPath, ref dirs); } //参数1 为要查找的总路径, 参数2 保存路径 private static void GetDirs(string dirPath, ref List<string> dirs) { foreach (string path in Directory.GetFiles(dirPath)) { //获取所有文件夹中包含后缀为 .prefab 的路径 if (System.IO.Path.GetExtension(path) == ".prefab") { dirs.Add(path.Substring(path.IndexOf("Assets"))); Debug.Log(path.Substring(path.IndexOf("Assets"))); } } if (Directory.GetDirectories(dirPath).Length > 0) //遍历所有文件夹 { foreach (string path in Directory.GetDirectories(dirPath)) { GetDirs(path, ref dirs); } } } }
相关文章推荐
- Unity中获取特定文件夹下文件名包含特定字符串的文件路径
- JAVA 一个简单的文件写入代码(遍历文件夹获取所有文件、写入缓冲池、获取文件绝对路径、按后缀名过滤文件)
- VBS遍历文件或文件夹路径输入文件的所有绝对路径(附源码)
- 利用递归算法遍历所有文件并打印文件绝对路径(包括文件夹)
- 【C++】遍历文件夹下的图片文件,并返回其路径
- php遍历指定路径下的所有文件和文件夹
- C++遍历文件夹(包含子文件夹中的文件)
- 遍历文件夹找到 扩展名为 fileextension的文件路径
- 新建Unity项目后包含的文件路径都是什么?
- c#如何实现对指定路径文件夹的遍历并复制里面所有文件到指定路径
- c++遍历查找文件夹路径下的所有文件(比如.txt) 使用的是MFC的CFileFind类
- 使用递归方式遍历指定磁盘路径下的文件及文件夹
- php 遍历文件夹及文件,获取文件名和文件路径存入数据库中
- 新建Unity项目后包含的文件路径都是什么?
- Windows和Linux下枚举(遍历)当前文件夹下所有文件完整路径的命令行
- 在java中如何遍历某个路径下的所有文件夹和文件
- 使用php scandir()函数遍历文件夹并输出所有文件路径
- 使用php scandir()函数遍历文件夹并输出所有文件路径
- 【Python】遍历某目录下的所有文件夹与文件的路径、输出中文乱码问题
- 新建Unity项目后包含的文件路径都是什么?