How to Delete ALL .txt files From a Directory using PHP

Ron picture Ron · Oct 13, 2012 · Viewed 12.9k times · Source

Im trying to Delete ALL Text files from a directory using a php script.

Here is what I have tried.....

<?php array_map('unlink', glob("/paste/*.txt")); ?>

I dont get an Error when I run this, yet It doesnt do the job.

Is there a snippet for this? Im not sure what else to try.

Answer

Baba picture Baba · Oct 13, 2012

Your Implementation works all you need to do is use Use full PATH

Example

$fullPath = __DIR__ . "/test/" ;
array_map('unlink', glob( "$fullPath*.log"))