symphonycms/symphony-2 — Issue #833: Add General::deleteFolder
Author: vlad-ghita
Created: 2011-10-17 09:39:06+00:00
State: open

What about improving file and folder management Symphony provides?

Currently there is no built-in way to delete a folder. Perhaps something like this could do the trick? (taken from [php.net](http://www.php.net/manual/en/function.unlink.php#102565))

public static function deleteFolder($tmp_path){
if (!is_writeable($tmp_path) && is_dir($tmp_path)){
chmod($tmp_path,0777);
}

$handle = opendir($tmp_path);
while ($tmp=readdir($handle)){
if ($tmp!='..' && $tmp!='.' && $tmp!=''){
if (is_writeable($tmp_path.DS.$tmp) && is_file($tmp_path.DS.$tmp)){
unlink($tmp_path.DS.$tmp);
}
elseif (!is_writeable($tmp_path.DS.$tmp) && is_file($tmp_path.DS.$tmp)){
chmod($tmp_path.DS.$tmp,0666);
unlink($tmp_path.DS.$tmp);
}

if (is_writeable($tmp_path.DS.$tmp) && is_dir($tmp_path.DS.$tmp)){
self::deleteFolder($tmp_path.DS.$tmp);
}
elseif (!is_writeable($tmp_path.DS.$tmp) && is_dir($tmp_path.DS.$tmp)){
chmod($tmp_path.DS.$tmp,0777);
self::deleteFolder($tmp_path.DS.$tmp);
}
}
}
closedir($handle);
rmdir($tmp_path);

return !is_dir($tmp_path);
}