Hey evyerone,

I'm currently working on a small project that would basically be a self hosted music server. Below is my code which, at a high level, goes through every music file in a specified directory and populates a multidimensional array with the ID3 tags and the file name. I was hoping someone could give me an idea on how to speed this up. It works for a small amount of music but with massive amounts of files, its just not practicle.

//Directory that contains music
string musicDirectory = "F:\\My Music\\";

//2D Array to hold each song and its info
string[][] list = new string[Directory.GetFiles(musicDirectory, "*.mp3", SearchOption.AllDirectories).Length][];

//Itterate through the directories and populate array
int i = 0;
foreach (string filePath in Directory.GetFiles(musicDirectory, "*.mp3", SearchOption.AllDirectories)) {
    ID3 obj = new ID3(filePath);

    list[i] = new string[6];
    list[i][0] = obj.FilePath;
    list[i][1] = obj.Artist;
    list[i][2] = obj.Album;
    list[i][3] = obj.Title;
    list[i][4] = obj.Genre;
    list[i][5] = obj.TrackNumber;


What it basically does is go through each file name and pass it as a constructor paramater to the class, ID3 which initializes the class variables. These are in turn, set to the proper array fields. This array would then be used to populate list boxes on an ASP.net webpage.

Any help would be much appreciated.


9 Years
Discussion Span
Last Post by JerryShaw

Unfortunately, you are dealing with fileIO and things will get slow. What you can try IMO is saving the information into an xml file, or SQL database. Then the next time you run the program it will load from the data store.

Another thing to try is parcing the directories out, and launch a thread for each directory to gather the information.

If this were my website project, I would have a seperate app running in the taskbar that would monitor changes to the directories, and automatically update my SQL database when a change occurs. Then when the web page is requested, it would get the data from the SQL database and completely avoid the FileIO.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.