# Load all content from folder

I want to ask, is there way to load in xna all content from folder ?
For example in my content I have:

Images/hero
Images/car
Images/tree

I want to make something like this

Dictionary<string,Model> models = new ...

foreach(string name in content.getNames("Images"))
{
}

-

There's a great MSDN page about a useful directory access method and someone's asked a similar question on StackOverflow.

Basically, find the files that are in that directory, initialise an array of that size and then iterate through those files, loading in the resources.

-
It's not static, but there is a Content property on the Game class which is commonly used in XNA. –  Michael Coleman Jun 16 '11 at 23:25
@Omnion Thanks for the correction -- edited. –  Anko Jun 16 '11 at 23:33
Actually the answer that you linked is an extension method for the ContentManager class. So you'd use it as Content.LoadContent<Texture2D>("myFolder"). The Content property on Game is simply an instance of the ContentManager class - you could use any instance you like. (Nothing about this has changed between XNA versions.) –  Andrew Russell Jun 17 '11 at 1:22
@Andrew Thank you! I've deleted my false and pointless note. –  Anko Jun 17 '11 at 10:53

http://xbox.create.msdn.com/en-US/sample/contentmanifestextensions

It's a tutorial about loading content at runtime. It shows how to generate a list automatically by using the content pipeline.

-

You can easily list all the files inside a folder and then load them one by one. By default all content files are stored in a folder right beside your main application so you just need to check for the contents of that direction. You can also use a recursive function if you want to load all files from all the directories. here is a little sample:

string[] files = Directory.GetFiles("content\\Images");
for (int i = 0; i < files.Count(); i++)
{