Search code examples
delphiglobdelphi-6

How can I find all MP3 files in a directory?


I recently started with delphi and now I want to get all mp3 files from a directory. I want something like the php function glob().


Solution

  • The old way of doing it is approx:

    var
      status : dword;
      sr : TSearchRec;
    begin
      status := FindFirst('*.mp3',faAnyFile,sr);
      while status = 0 do
      begin
    
         // sr.Name is the filename; add it to a list
         // or something. Note there is no path so you
         // may need to add that back on somewhere
    
         status := FindNext(sr);
      end;
      SysUtils.FindClose(sr);
    
      // ...
    end;