Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

unlink

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.

like image 987
Ron Avatar asked Oct 13 '12 03:10

Ron


1 Answers

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

Example

$fullPath = __DIR__ . "/test/" ;
array_map('unlink', glob( "$fullPath*.log"))
like image 178
Baba Avatar answered Sep 30 '22 15:09

Baba