/** * Remove a file or directory and it's contents * */ public static function RmAll($path) { if (empty($path)) { return false; } if (is_link($path)) { return @unlink($path); } if (!is_dir($path)) { return @unlink($path); } $success = true; $subDirs = array(); //$files = scandir($path); $files = gpFiles::ReadDir($path, false); foreach ($files as $file) { $full_path = $path . '/' . $file; if (!is_link($full_path) && is_dir($full_path)) { $subDirs[] = $full_path; continue; } if (!@unlink($full_path)) { $success = false; } } foreach ($subDirs as $subDir) { if (!gpFiles::RmAll($subDir)) { $success = false; } } if ($success) { return gpFiles::RmDir($path); } return false; }
/** * Remove the custom css file for a layout * */ function RemoveCSS($layout) { global $dataDir; $dir = $dataDir . '/data/_layouts/' . $layout; $path = $dir . '/custom.css'; if (file_exists($path)) { unlink($path); } $path = $dir . '/index.html'; if (file_exists($path)) { unlink($path); } if (file_exists($dir)) { gpFiles::RmDir($dir); } }
/** * Remove all the contents of a directory * */ function EmptyDir($dir) { if (!file_exists($dir)) { return true; } if (is_link($dir)) { return unlink($dir); } $dh = @opendir($dir); if (!$dh) { return false; } $dh = @opendir($dir); if (!$dh) { return false; } $success = true; $subDirs = array(); while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') { continue; } $fullPath = $dir . '/' . $file; if (is_link($fullPath)) { if (!unlink($fullPath)) { $success = false; } continue; } if (is_dir($fullPath)) { $subDirs[] = $fullPath; continue; } if (!unlink($fullPath)) { $success = false; } } closedir($dh); foreach ($subDirs as $subDir) { if (!$this->EmptyDir($subDir)) { $success = false; } if (!gpFiles::RmDir($subDir)) { $success = false; } } return $success; }