//Function to find all music files and add to database public void GetMusicFiles(string rootDirectory) { int numberOfFilesAdded = 0; Queue<string> directories = new Queue<string>(); List<string> paths = new List<string>(); directories.Enqueue(rootDirectory); while (directories.Count > 0) { string directory = directories.Dequeue(); try { paths = new List<string>(Directory.GetFiles(directory, "*.mp3")); } catch (Exception ex) { Console.WriteLine("[Database Population] "+ex.Message); } if (paths.Count() > 0) { foreach (string file in paths) { if (!Repository.Instance.isDuplicate(file)) { Repository.Instance.addSongToDatabase(file); numberOfFilesAdded++; } } } //Search for sub directories try { paths = new List<string>(Directory.GetDirectories(directory)); } catch (Exception ex) { Console.WriteLine("[Database Population] "+ex.Message); } if (paths.Count() > 0) { foreach (string subDir in paths) { directories.Enqueue(subDir); } } } if (numberOfFilesAdded < 1) { Console.WriteLine("[Database Population] No music files found."); } else { Console.WriteLine("[Database Population] Added " + numberOfFilesAdded.ToString() + " files to the database"); } }
//Function to find all music files and add to database public void GetMusicFiles(string rootDirectory) { Queue<string> directories = new Queue<string>(); List<string> paths = new List<string>(); directories.Enqueue(rootDirectory); while (directories.Count > 0) { string directory = directories.Dequeue(); try { paths = new List<string>(Directory.GetFiles(directory, "*.mp3")); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (paths.Count() > 0) { foreach (string file in paths) { Repository add = new Repository(); add.addSongToDatabase(file); } } //Search for sub directories try { paths = new List<string>(Directory.GetDirectories(directory)); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (paths.Count() > 0) { foreach (string subDir in paths) { directories.Enqueue(subDir); } } } }