public function read($path)
 {
     $dir = new Folder($path);
     $read = $dir->read();
     $result = [];
     foreach ($read[0] as $folder) {
         $info = new Folder($path . DS . $folder);
         $reference = Router::fullBaseUrl() . '/' . $this->toRelative($path . '/' . $folder);
         $data = ['name' => $folder, 'type' => 'folder', 'path' => $path . DS . $folder, 'reference' => $reference, 'extension' => 'folder', 'size' => $info->dirsize()];
         $result[] = $data;
     }
     foreach ($read[1] as $file) {
         $info = new File($path . DS . $file, false);
         $reference = Router::fullBaseUrl() . '/' . $this->toRelative($path . '/' . $file);
         $data = ['name' => $info->info()['basename'], 'type' => 'file', 'path' => $path, 'reference' => $reference, 'extension' => $info->info()['extension'], 'size' => $info->info()['filesize']];
         $result[] = $data;
     }
     return $result;
 }
 /**
  * main method
  *
  * @param  string $tempDir an other directory to clear of all folders and files, if desired
  * @return void
  */
 public function main($tempDir = null)
 {
     if (empty($tempDir)) {
         $tempDir = Configure::read('Attachments.tmpUploadsPath');
     }
     if (!Folder::isAbsolute($tempDir)) {
         $this->out('The path must be absolute, "' . $tempDir . '" given.');
         exit;
     }
     $Folder = new Folder();
     if ($Folder->cd($tempDir) === false) {
         $this->out('Path "' . $tempDir . '" doesn\'t seem to exist.');
         exit;
     }
     $dir = new Folder($tempDir);
     $folders = $dir->read();
     $files = $dir->findRecursive();
     $deletedFiles = 0;
     $deletedFolders = 0;
     $this->out('Found ' . count($folders[0]) . ' folders and ' . count($files) . ' files');
     foreach ($files as $filePath) {
         $file = new File($filePath);
         // only delete if last change is longer than 24 hours ago
         if ($file->lastChange() < time() - 24 * 60 * 60 && $file->delete()) {
             $deletedFiles++;
         }
         $file->close();
     }
     foreach ($folders[0] as $folderName) {
         $folder = new Folder($dir->pwd() . $folderName);
         // only delete if folder is empty
         if ($folder->dirsize() === 0 && $folder->delete()) {
             $deletedFolders++;
         }
     }
     $this->out('Deleted ' . $deletedFolders . ' folders and ' . $deletedFiles . ' files.');
 }