Updated cd-root.ps1

This commit is contained in:
Markus Fleschutz 2025-05-30 10:15:19 +02:00
parent b24233e4b7
commit 391c93f9d5

View File

@ -1,11 +1,11 @@
<# <#
.SYNOPSIS .SYNOPSIS
Sets the working directory to the root directory Sets the working dir to the root dir
.DESCRIPTION .DESCRIPTION
This PowerShell script changes the current working directory to the root directory (C:\ on Windows). This PowerShell script changes the current working directory to the root directory (C:\ on Windows).
.EXAMPLE .EXAMPLE
PS> ./cd-root PS> ./cd-root.ps1
📂C:\ entered (has 0 files and 7 folders) 📂C:\ with 7 folders and 0 files entered.
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -13,11 +13,11 @@
#> #>
try { try {
if ($IsLinux) { $path = "/" } else { $path = "C:\" } if ($IsLinux -or $IsMacOS) { $path = "/" } else { $path = "C:\" }
Set-Location "$path" Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory $folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" $files = Get-ChildItem $path -attributes !Directory
"📂$path with $($folders.Count) folders and $($files.Count) files entered."
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0])" "⚠️ Error: $($Error[0])"