deleting all files in except the one running the delete code

后端 未结 2 754
一生所求
一生所求 2021-01-26 03:51

I want to delete all the files in the public_html directory of my domain by a single command. For this one of SO\'s questions had this answer:



        
2条回答
  •  北海茫月
    2021-01-26 04:09

    Use something like this:

    function delete_all($filename) {
        // files listed in this array will not being deleted
        $exceptions = array (
            'file1',
            'file2', ...
        );
    
        if(!in_array($filename, $exceptions)) {
            unlink($filename);
        }
    }
    
    // !!! attention !!! this will delete all files except those listed above
    // from this folder. Make sure you know what you are doing
    array_map('delete_all', glob("path/to/temp/*"));
    

提交回复
热议问题