Only include later subdirectories in file string C# -
i'm trying write nifty content loader in xna avoid having individually load each asset. however, i'm having trouble describing directory locations because default directory file operations location of exe, xna's content.load uses default directory of content folder.
foreach (string subd in directory.getdirectories("..\\..\\..\\..\\happy workercontent\\gfx\\", "*.*", searchoption.alldirectories)) { foreach (string s in directory.getfiles(subd)) { string file = path.getfilenamewithoutextension(s); if (enum.isdefined(typeof(tex), file)) { console.writeline(subd); console.writeline(file); gxdict.add(path.getfilenamewithoutextension(s), gv.c_game1.content.load<texture2d>(subd + "\\" + file)); } } }
my error because subd is, example, "........\happy workercontent\gfx\level entities\terrains", content.load expects "gfx\level entities\terrains".
i subd.substring(32), seems messy, if rename folders or later (and may not work in published version?). there way "i want part of file after "happy workercontent" directory?
you write method return text following particular target string.
then if needed search different string, you'd need pass different target string method.
for example:
// returns contents of text following target string, // or "" if target string wasn't found. public static string contentafter(string text, string target) { int index = text.indexof(target); if (index >= 0) return text.substring(index + target.length); else return ""; }
then you'd call like:
string test = "..\\..\\..\\..\\happy workercontent\\gfx\\whatever"; string target = "\\happy workercontent\\"; string following = contentafter(test, target);
that wouldn't work great if had 2 strings matching target string in text. method return text after first match, include second target string of course.
Comments
Post a Comment