i am new in php
i have upload all files and folders in public_html
to live my website, i don't know what was problem there in server but PaxHeader
named folder was automatically created in all my public_html like in css,js,admin, admin's js in every folder there is a folder named PaxHeader
so i want to make a script for delete that folder from all public_html
but basically i am a designer. so i know only few php code. any bodody help me for that
my folder structure is like :
-public_html
-PaxHeader
-js
-PaxHeader
-css
-PaxHeader
-admin
-PaxHeader
-js
-PaxHeader
-css
-PaxHeader
this structure is just example, PaxHeader
folder is in every folder of public_html
and evry PaxHeader
folder has some files, how i can delete by script of php
?
I wrote a simple php code for you.
$basepath = "/home/mohsen/Desktop/public_html/";
$dirNameToRemove = "PaxHeader";
function findAndRemove($path)
{
global $dirNameToRemove;
$items = scandir($path);
foreach($items as $item)
{
if(!is_dir($path . $item) || $item == '.' || $item == '..')
continue;
if($item == $dirNameToRemove)
{
#remove directory
rmdir($path . $item);
}
else
{
findAndRemove($path . $item . "/");
}
}
}
findAndRemove($basepath);
$basepath variable is a base path to your public_html directory $dirNameToRemove variable is the name of directory you want to delete recursive.
Enjoy it!
You'll need to write something like that (untested)
function deleteDir($dirPath) {
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
self::deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
function removepaxdir($path) {
$dir=opendir($path);
while ($FileName=readdir($dir))
{
if(is_dir($FileName))
{
if($FileName=='PaxHeader') deleteDir($path.$FileName);
else removepaxdir($path.$FileName);
}
}
}
removepaxdir('.');