Skip to content

Instantly share code, notes, and snippets.

@fum1h1ro
Created April 16, 2012 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fum1h1ro/2397362 to your computer and use it in GitHub Desktop.
Save fum1h1ro/2397362 to your computer and use it in GitHub Desktop.
Assetsフォルダのファイル一覧を取得する
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
// Assetsフォルダ以下を見てファイルを取得する系
public class AssetDir {
public static string[] GetFiles(string path) {
string[] rawfiles = Directory.GetFiles(MakePath(path));
string[] files = new string[rawfiles.Length];
int idx = 0;
foreach (string s in rawfiles)
files[idx++] = Path.GetFileName(s);
return FilterIgnoreEntries(files);
}
// extに拡張子を与えると該当するファイルのみ取得します
// 拡張子リストを | で区切ると複数指定できます -> ".fbx|.prefab"
public static string[] GetFiles(string path, string ext) {
string[] files = GetFiles(path);
ext = ext.ToLower();
string[] exts = ext.Split('|');
string[] filtered =
Array.FindAll(files,
delegate(string name) {
return
Array.IndexOf(exts, Path.GetExtension(name).ToLower()) >= 0;
});
return filtered;
}
private static string MakePath(string path) {
return Application.dataPath + "/" + path;
}
private static string[] FilterIgnoreEntries(string[] files) {
return
Array.FindAll(files,
delegate(string name) {
return
Path.GetFileName(name).IndexOf('.') != 0 &&
Path.GetExtension(name).ToLower() != ".meta";
});
}
}
@fum1h1ro
Copy link
Author

ファイル名のみにしてみた

@fum1h1ro
Copy link
Author

拡張子を複数指定できるようにした

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment