I have a folder with many file , and i need to perform a deletion with certain file and those file have a pattern like
messages.bm.inc.php
messages.cn.inc.php
messages.en.inc.php
Those file are dynamically created , but the pattern is there
Before this i normally delete my file with below code , and repeat it
$filename="messages.en.inc.php";
if (file_exists($filename)) {
unlink($filename);
}
Now i having a more dynamic situation , i need search through those file with the patern and delete it , please suggest a way to do , thanks
By
glob
you will get all your files from folder by specified pattern,array_map
will implementunlink
function for array of matched files.Use the PHP glob() function to get the list of the files by pattern and delete using the loop.