I need the last 7 days' storage logs to move a new folder. But, I can't move them and got this error.
rename(/var/www/html/eMarketing/storage/logs/old-log-2020-02-27,/var/www/html/eMarketing/storage/logs/laravel-2020-02-27.log): Not a directory
My Code is here
public function logs()
{
$today = \Carbon\Carbon::today()->format('Y-m-d');
$days = \Carbon\Carbon::today()->subDays(7)->format('Y-m-d');
$newDirectoryPath = storage_path('logs/old-log-'.$days);
if (!\File::isDirectory($newDirectoryPath)) {
\File::makeDirectory($newDirectoryPath);
}
$path = storage_path('logs/');
$allFiles = \File::allFiles($path);
foreach($allFiles as $files) {
$file = pathinfo($files);
$logDay = str_replace('laravel-','', $file['filename']);
if ($logDay >= $days && $logDay < $today) {
\File::move($newDirectoryPath, $path.$file['basename']);
}
}
}