How to ignore all files except MP3?

The place for "I can't figure out how to..." questions.
Post Reply
Assmonkey
User
Posts: 1
Joined: Fri Apr 20, 2007 12:52 pm

How to ignore all files except MP3?

Post by Assmonkey » Fri Apr 20, 2007 12:56 pm

I'm using getid3 in a php script that generates directory listings but I've run into some problems.
When the php script generates the dir listing, it will also echo an entry for the parent dir i.e. "../" and this makes getid3 go bonkers. It doesn't error out or die but it fills my event log with errors about not being able to process that particular file.
So is there any way I can make getid3 ignore that entry? Or make getid3 only read mp3 files?

Thanks for this great script and thanks in advance for any help. :)

diablo_man5666
User
Posts: 1
Joined: Sat Sep 22, 2007 3:04 am
Location: USA

Post by diablo_man5666 » Sat Sep 22, 2007 3:20 am

What type of loop are you using to run through the directory?

If you are nesting a for loop inside a while loop, you can have the for loop ignore files named things like '.' or '..', for example:

Code: Select all

require_once('getid3.php');

$dir_handle  = @opendir($path) or die("Unable to open $path");

while ($file = readdir($dir_handle)) {

$getID3 = new getID3;

if ($file == "." || $file == ".." || $file != "mp3$")
continue;

$fileinfo = $getID3->analyze($file);

echo "$file";

closedir($dir_handle);

}

Post Reply