/** * @return bool */ public function execute() { $files = $this->filesystem->listWith(['timestamp'], $this->directoryPath, false); foreach ($files as $file) { if ($file['timestamp'] < $this->olderThan->getTimestamp()) { $this->filesystem->delete($file['path']); } } }
/** * Get a list of PDF files in the local filesystem at a given relative path. * * @param string $path * * @return array Array of PDF files */ public function getPDFFiles($path) { $files = []; $contents = $this->localFilesystem->listWith(['mimetype', 'path'], $path); foreach ($contents as $content) { if ($this->contentIsPdf($content)) { $files[] = $content; } } // Sort files to keep the order sort($files); return $files; }
function it_should_execute_the_delete_old_files_command(Filesystem $filesystem, DateTime $olderThan) { $filesystem->listWith(['timestamp'], '/dir', false)->willReturn([['path' => '/dir/file-new.gz', 'timestamp' => 2000], ['path' => '/dir/file-old.gz', 'timestamp' => 1000], ['path' => '/dir/file-older.gz', 'timestamp' => 500]]); $olderThan->getTimestamp()->willReturn(1500); $filesystem->delete('/dir/file-older.gz')->shouldBeCalled(); $filesystem->delete('/dir/file-old.gz')->shouldBeCalled(); $this->beConstructedWith($filesystem, '/dir', $olderThan); $this->execute(); }
protected function searchFilesWithByPattern(array $keys = [], $pattern, $recursive = false, $is = null) { $result = []; foreach (parent::listWith($keys, '', $recursive) as $data) { if (isset($is) && $data['type'] !== $is) { continue; } if (preg_match($pattern, $data['path'])) { $result[] = $data; } } return $result; }