unity3d 依据指定的Assets下的目录路径 返回这个路径下的全部文件名称
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
<pre class="csharp" name="code"> public static List<string> nameArray = new List<string>();
/// <summary>
/// 依据指定的 Assets下的文件路径 返回这个路径下的全部文件名称//
/// </summary>
/// <returns>文件名称数组</returns>
/// <param name="path">Assets下“一"级路径</param>
/// <param name="pattern">筛选文件后缀名的条件.</param>
/// <typeparam name="T">函数模板的类型名t</typeparam>
void GetObjectNameToArray<T>(string path, string pattern)
{
string objPath = Application.dataPath + "/" + path;
string[] directoryEntries;
try
{
//返回指定的文件夹中文件和子文件夹的名称的数组或空数组
directoryEntries = System.IO.Directory.GetFileSystemEntries(objPath); for(int i = 0; i < directoryEntries.Length ; i ++){
string p = directoryEntries[i];
//得到要求文件夹下的文件或者文件夹(一级的)//
string[] tempPaths = StringExtention.SplitWithString(p,"/Assets/"+path+"\\"); //tempPaths 切割后的不可能为空,仅仅要directoryEntries不为空//
if(tempPaths[1].EndsWith(".meta"))
continue;
string[] pathSplit = StringExtention.SplitWithString(tempPaths[1],".");
//文件
if(pathSplit.Length > 1)
{
nameArray.Add(pathSplit[0]);
}
//遍历子文件夹下 递归吧! else
{
GetObjectNameToArray<T> (path+"/"+pathSplit[0], "pattern");
continue;
}
}
}
catch (System.IO.DirectoryNotFoundException)
{
Debug.Log("The path encapsulated in the " + objPath + "Directory object does not exist.");
}
}
void Start () {
//TextAsset[] texts = LoadAsset<TextAsset> ("/CreateScriptDialog/Editor", "cs");
//GetObjectNameToArray<string> ("uSequencer/Example Scenes", "xxx"); //能够实现嵌套遍历
GetObjectNameToArray<string> ("uSequencer", "xxx"); //能够实现嵌套遍历
foreach (string str in nameArray) {
Debug.Log(str);
}
}
<pre class="csharp" name="code">/// <summary>
/// 自己定义的字符串切割的方法
/// </summary>
public class StringExtention { public static string[] SplitWithString(string sourceString, string splitString){
string tempSourceString = sourceString;
List<string> arrayList = new List<string>();
string s = string.Empty;
while (sourceString.IndexOf(splitString) > -1) //切割
{
s = sourceString.Substring(0, sourceString.IndexOf(splitString));
sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);
arrayList.Add(s);
}
arrayList.Add(sourceString);
return arrayList.ToArray();
}
}
unity3d 依据指定的Assets下的目录路径 返回这个路径下的全部文件名称的更多相关文章
- nginx 同一域名下分目录配置显示php,html,资源文件
安装上nginx后 注意后nginx.conf 中的这么几行 error_log /var/log/nginx/error.log; 日志,这个很有用 include /etc/nginx/conf ...
- [记录]Ubuntu下,使用Shell,简单替换有规律的文件名称
因工作中需要将Flash转为Html5,并且要有动画效果,我将Flash的组件导出Png序列,然后将Png序列拼接成一张雪碧图(Sprite),名字为在生成雪碧图可以排序,需要改成数字名称. 而名字是 ...
- TDirectory.GetDirectories 获取指定目录下的目录
使用函数: System.IOUtils.TDirectory.GetDirectories 所有重载: class function GetDirectories(const Path: strin ...
- 在Linux下和Windows下遍历目录的方法及如何达成一致性操作
最近因为测试目的需要遍历一个目录下面的所有文件进行操作,主要是读每个文件的内容,只要知道文件名就OK了.在Java中直接用File类就可以搞定,因为Java中使用了组合模式,使得客户端对单个文件和文件 ...
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
摘自:http://blog.csdn.net/forandever/article/details/5711319 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本 ...
- 2.获取指定目录及子目录下所有txt文件的个数,并将这些txt文件复制到F盘下任意目录
package cn.it.text; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ...
- IO流-递归遍历目录下指定后缀名结尾的文件名称
/* *自定义遍历目录下指定后缀名结尾文件的名称的方法: * * param file:指定目录 name:指定后缀名 */ 1 public static void FileName(File fi ...
- 【Lua】关于遍历指定路径下所有目录及文件
关于Lua中如何遍历指定文件路径下的所有文件,需要用到Lua的lfs库. 首先创建一个temp.lua文件,用编辑器打开: 要使用lfs库,首先需要把lfs库加载进来 require("lf ...
- C#中获取指定目录下所有目录的名称、全路径和创建日期
场景 指定一个路径,根据这个父级路径获取此目录下所有目录的名称.全路径.创建日期等信息. 注: 博客主页: https://blog.csdn.net/badao_liumang_qizhi 关注公众 ...
随机推荐
- UVA - 12232 Exclusive-OR (并查集扩展偏离向量)
Description You are not given n non-negative integersX0,X1,..., Xn-1 less than220, but they do exist ...
- mysqldump: Couldn't execute 'show events': Cannot proceed because system tables used by Event Schedu
最近将老版本的mysql 实例倒入 percona 5.5.30,使用的是线上的全备,结果将mysql 库下的表也倒入了,这下可悲剧了,备份报错. 没办法,将mysql库下的数据倒出来,清空,再倒入p ...
- Java 8 时间日期库的20个使用示例
java 8是如何处理时间及日期的 有人问我学习一个新库的最佳途径是什么?我的回答是,就是在实际项目中那样去使用它.在一个真实的项目中会有各种各样的需求,这会促使开发人员去探索和研究这个新库.简言之, ...
- iOS UIWebView 载入https 网站出现NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL,
今天在载入https网站的时候遇到例如以下的错误问题.所以对自己之前写的iOS内嵌webview做了一些改动,能够让它载入http网站也能够让它载入https网站. 以下是我载入https网站的时候出 ...
- "UBUNTU: SAUCE: apparmor: 3.0 backport of apparmor3"
下面提供的commit是为了让nexus 4g的内核支持ubunt touch的一些功能. 链接地址如下: "UBUNTU: SAUCE: apparmor: 3.0 backport of ...
- Mpmovieplayercontroller 黑屏
MPMoviePlayerController * moviePlayer; 原因是:你在声明movieplayer的时候,声明成为了局部变量,与此同一时候你的project支持ARC,所以会出现黑屏 ...
- 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern)
原文:乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) 作者:webabc ...
- iOS开发- Xcode插件(一)-规范凝视生成器VVDocumenter
分享几个经常使用的Xcode插件. 第一个, 规范凝视生成器VVDocumenter. 顾名思义, 它能够非常方便的为你自己主动加入�凝视 使用效果例如以下: 下载链接:https://github. ...
- Django架设blog步骤(转)
最近在研究Python,起初是因为想做个爬虫,昨天看了点基础教程,台湾辅仁大学的视频,了解了python的语法规范及语言特性,主要有三: 1.动态脚本语言: 2.语法简洁,强制缩进: 3.应用广泛,w ...
- SSL探03
本文探讨了Openssl的Engine机械.Openssl硬件引擎(Engine)可以使用户比較easy地将自己的硬件增加到openssl中去,替换其提供的软件算法. ENGINE 是 OPENSSL ...