Delete files and directories from a directory except a specific file with php

-1

I need to run a weekly cron to delete the files and directories that the prestashop cache generates except one, the index.php

I tried it with shell_exec () but my server has disabled that function for security reasons.

I appreciate your help!

a greeting

    
asked by Josegp 19.11.2017 в 19:43
source

1 answer

0

You can browse the files in a folder and validate that you do not erase the index, this is the code to go through it and delete the files

$files = glob('my_folder/*'); //obtenemos todos los nombres de los ficheros
foreach($files as $file){
if(is_file($file))
unlink($file); //elimino el fichero
}
    
answered by 22.12.2017 в 17:49