How can unity read a directory?

Hallo

I am making a sound list where the player of the game can put his/her own music in. But for that unity must read a directory outside the _data folder.

How can unity do that?

Does anybody know the answer?

I have something like it but it only reads the string.

var path = Application.dataPath+"/music/";
function Update ()
{
var files = (path+"*.mp3");
print(files);
}

Try this:

import System.IO;

var filesList = new Array();

function ReadDirectory() {

    var path = Application.dataPath+"\\music\\";    
    var info = new DirectoryInfo(path);
    var fileInfo = info.GetFiles();

    for (file in fileInfo)
    {

        var filename = file.ToString();    
        filename = filename.Replace(Application.dataPath+"\\music\\", "");          
        filesList.Push(filename);

    }

    print(filesList);
}

Here's another example, Desktop game?, showing how to read a file. Note that only standalone executables can read files on the player's machine. The web-browser version can not, for security reasons.

Unity will not automatically expand wildcards for you, like "*.mp3", that is something you need to using .Net directory functions.

Also - the Update() function runs every frame - you probably want to move your file-reading to a function that runs once, called either in Start(), or via button click or something.

On second reading - it's not clear from your question, if you mean to read files on the user's machine, or if you're allowing the user to upload files to your server. Can you clarify what you're asking for?

Use the System.IO library from .NET