В моем сервере у меня есть папки и подкаталогКак придавить папку в PHP
Я хочу, чтобы вызвать Свести METHODE в каталог, чтобы переместить каждые файлы на том же уровне, и удалить все пустые папки
Вот что я сделал до сих пор:
public function flattenDir($dir, $destination=null) {
$files = $this->find($dir . '/*');
foreach ($files as $file) {
if(!$destination){
$destination = $dir . '/' . basename($file);
}
if (!$this->isDirectory($file)) {
$this->move($file, $destination);
}else{
$this->flattenDir($file, $destination);
}
}
foreach ($files as $file) {
$localdir = dirname($file);
if ($this->isDirectory($localdir) && $this->isEmptyDirectory($localdir) && ($localdir != $dir)) {
$this->remove($localdir);
}
}
}
public function find($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$files = array_merge($files, $this->find($dir . '/' . basename($pattern), $flags));
}
return $files;
}
Этот код не показывают какую-либо ошибку на ходу, но resukt не как ожидалось.
Для Exemple, если у меня есть /folder1/folder2/file
я хочу иметь /folder2/file
как результат, но вот папки по-прежнему, как они где ...
Там не кажется, вопрос? Ваш общий подход, похоже, находится на пути. –
посмотрите http://stackoverflow.com/questions/1833518/remove-empty-subfolders-with-php и http://stackoverflow.com/questions/2398147/php-recursive-directory-path –
Имеете ли вы проблема с вашим скриптом? Любые ошибки? – chrislondon