PHP – Delete files by pattern

Martin Zeller php 1 Comment

If you want to delete files by pattern (e.g. „*.txt“) in a directory, you can do this with the php function glob!

$files = glob('/path/to/files/*.txt'); // finds all txt files in the directory /path/to/files/
foreach($files as $file)
  unlink($file);

With this method you can also delete all files of a directory – with pattern *.*

Comments 1

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.