To delete all files of a particular extension, or in fact, delete a group with any wildcard, echo `rm -f path/to/*.jpg`; # note the backquotes, not single nor double quotes or foreach (glob("*.jpg") as $filename) { echo "$filename size " . filesize($filename) . "\n"; unlink($filename); } sometimes, the function realpath() may be needed: unlink(realpath($fileName)); or $mask = "*.jpg" array_map( "unlink", glob( $mask ) );...