PowerShell/scripts/cd-logs.ps1
2025-04-23 13:22:05 +02:00

32 lines
800 B
PowerShell
Executable File

<#
.SYNOPSIS
Sets the working directory to the logs folder
.DESCRIPTION
This PowerShell script changes the current working directory to the logs directory.
.EXAMPLE
PS> ./cd-logs
📂/var/logs entered (has 3 files and 2 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function GetLogsDir {
if ($IsLinux -or $IsMacOS) { return "/var/logs" }
$WinDir = [System.Environment]::GetFolderPath('Windows')
return "$WinDir\Logs"
}
try {
$path = GetLogsDir
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
exit 1
}