Write physically files from resource folder into harddrive

Hello,

Besides txt filetypes I have some png-files in the levels folder of the resources folder that should be created as physically .png files in the datapath of the standalone:

foreach(TextAsset example in (TextAsset[])Resources.LoadAll("Levels"))
	File.WriteAllText(Application.dataPath+"/Resources/Levels/"+example.name+".png",
    example.text);

But I get an error: Cannot cast from source type to destination type.

Resources.LoadAll returns object and that is not exactly meant to be cast to TextAsset.

From what i see, your code should be

foreach(var item in Resoureces.LoadAll("levels"))
{
TextAsset asset = (TextAsset)item;
....    
}

I don’t think you can cast a TextAsset as an image. It needs to be in byte format. Take a look at these two links:

http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html
http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToPNG.html