title: Reading and selecting files using dirent.h in C
body: <p>I'm new into programming microcontrollers, and I have a problem.</p>
  
  <p>I'm trying to make a device that plays music from USB. I can read from USB, but I have no idea how to choose a certain file. I'm using <code>dirent</code>.</p>
  
  <p>My code so far:</p>
  
  <pre><code>while (true) {
      USBHostMSD msd("usb");
       //setup PWM hardware for a Class D style audio output
      PWMout.period(1.0/400000.0);
  
      // wait until connected to a USB device
      while(!msd.connect()) {
          Thread::wait(500);
      }
  
      FILE *wave_file;
      lcd.cls();
      lcd.locate(0,3);
  
  
      DIR *dir;
      struct dirent *ent;
      int i=0;
      int stevilo_datotek =0;
  
  
      dir = opendir ("/usb/");
      if (dir != NULL) 
      {
  
  
          while ((ent = readdir (dir)) != NULL) 
          {   
                lcd.printf ("%s\n", ent-&gt;d_name[0]);  
          }
  }
  </code></pre>
  
  <p>Now this code displays what's on USB. How can I navigate through files on USB using the buttons on the device? I'd like to know if there's a way to assign certain song a certain number so I can navigate. I've studied <code>dirent.h</code> file for so long, and I can't find where <code>dirent</code> saves the file order (if it does).</p>