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 关注公众 ...
随机推荐
- surfaceDestroyed什么时候被调用
今天看别人的代码,突然有个疑问,surfaceDestroyed这个函数什么时候被调用呢? 上网搜了一番,基本都说是surface被销毁的时候,才会调用surfaceDestroyed.问题又来了su ...
- Android数据库专家秘籍(七)经验LitePal查询艺术
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/40153833 经过了多篇文章的学习,我们已经把LitePal中的绝大部分内容都掌握 ...
- Eclipse 打JAR包,插件FatJar 安装与使用
下载fatJar插件,解压缩后是一个.../plugins/(net...)把plugins下面的(net..)文件夹拷贝到eclipse的plugins下,重新启动Eclipse3.1,Window ...
- 查看linux信息
1.操作系统内核 cat /proc/version 2.操作系统版本 head -n 1 /etc/issue # 查看操作系统版本 3.查看cpu信息 more /proc/cpuinfo --- ...
- jQuery 焦点图,图像文件js档
jQuery 焦点图,图片文件在js文件里 演示 XML/HTML Code <div id="photo_container"></div> JavaSc ...
- 【C语言探索之旅】 第二课:工欲善其事,必先利其器
内容简介 1.课程大纲 2.第一部分第二课:工欲善其事,必先利其器 3.第一部分第三课预告:你的第一个程序 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C ...
- GitLab一键式安装bitnami
https://bitnami.com/stack/gitlab/installer https://bitnami.com/redirect/to/96764/bitnami-gitlab-8.5. ...
- paip.jdk1.4 1.5(5.0) 1.6(6.0) 7.0 8.0特点比较与不同
paip.jdk1.4 1.5(5.0) 1.6(6.0) 7.0 8.0特点比较与不同 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地 ...
- C#启动进程之Process
在程序设计中,我们经常会遇到要从当前的程序跳到另一个程序的设计需求.也就是当前进程创建另一个进程.C#提供了Process使得我们很方便的实现. 1.Process基本属性和方法 Id //进程的Id ...
- 我学cocos2d-x (两) 采用Delegate(信托)
Delegate(信托)什么 Delegate是ios开发中的一个概念,主要是为了让类A中的功能,放到类B中来实现,这样能够合理的把功能划分到不同的文件里进行实现,从而更好的实现模块的分离.如UIAp ...