This is a relatively implemented function. We can customize the directories to be deleted and save them in one data. Then, we can traverse the data and delete the specified files in the directory. The Code is as follows. This is a relatively implemented function. We can customize the directories to be deleted and save them in one data. Then, we can traverse the data and delete the specified files in the directory. The Code is as follows.
Script ec (2); script
Directly run the Code:
The following example shows how to delete the html of a specified directory. If you want other files, you only need to change the html to the suffix you want to delete.
The Code is as follows: |
|
$ Lanmu = array ("action", "tiyu", "yizhi", "sheji", "gaoxiao", "maoxian", "qipai", "celue ", "minjie", "xiuxian", "ertong", "jingying", "webgame "); Foreach ($ lanmu as $ v2 ){ $ Mstdel [] = glob (getcwd (). DIRECTORY_SEPARATOR. $ v2.DIRECTORY _ SEPARATOR. '[1-9] *. html '); } // Var_dump ($ mstdel ); // Var_dump (count ($ mstdel )); $ I = 0; Foreach ($ mstdel as $ val ){ Foreach ($ val as $ val2 ){ // Echo $ val2 ." "; If (unlink ($ val2) $ I ++; // $ Countval2 [] = $ val2; } } Echo 'del success: '. $ I; // Echo count ($ countval2 ); // Var_dump (glob (getcwd (). DIRECTORY_SEPARATOR. 'sheji'. DIRECTORY_SEPARATOR. '[1-9] *. html ')); // Var_dump (glob ('./sheji/[1-9] *. html ')); // Var_dump (glob ('./sheji/[^ index] *. html ')); // Array_walk (glob (getcwd (). '/sheji/[1-9] *. html'), 'unlink '); // Array_walk (glob ('./sheji/[1-9] *. html'), 'unlink '); // Array_walk (glob (getcwd (). DIRECTORY_SEPARATOR. 'sheji'. DIRECTORY_SEPARATOR. '[1-9] *. html'), 'unlink '); // Var_dump (DIRECTORY_SEPARATOR ); // Var_dump (unlink ('d: shanmaowwwwroottiantangtvxyxh4cc/sheji/20312.html ')); ?> |