{"id":11,"date":"2015-05-02T03:26:40","date_gmt":"2015-05-02T01:26:40","guid":{"rendered":"http:\/\/lab.fawno.com\/?p=11"},"modified":"2022-03-07T00:48:59","modified_gmt":"2022-03-06T23:48:59","slug":"","status":"publish","type":"post","link":"https:\/\/lab.fawno.com\/en\/2015\/05\/02\/borrar-un-directorio-de-forma-recursiva\/","title":{"rendered":"","raw":""},"content":{"rendered":"","protected":false,"raw":""},"excerpt":{"rendered":"","protected":false,"raw":""},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_es_post_content":"\n
En ocasiones quieres borrar desde PHP un directorio contenga lo que contenga... para esa tarea cree esta funci\u00f3n:<\/p>\n\n\n\n
function rd ($path) {\n foreach (array_diff(scandir($path), ['', '.', '..']) as $file) {\n if (is_file($path . DIRECTORY_SEPARATOR . $file)) {\n unlink($path . DIRECTORY_SEPARATOR . $file);\n } else {\n rd($path . DIRECTORY_SEPARATOR . $file);\n }\n }\n rmdir($path);\n}<\/pre>\n\n\n\nHace a\u00f1os que la cree y por tanto seguro que es mejorable, pero cumple su funci\u00f3n a la perfecci\u00f3n.<\/p>\n\n\n\n