mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-11 13:53:42 +02:00
Updated cd-windows.ps1
This commit is contained in:
@ -1,11 +1,11 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Sets the working directory to the Windows directory
|
Sets the working dir to the Windows directory
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script changes the working directory to the Windows directory.
|
This PowerShell script sets the current working directory to the Windows directory.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-windows
|
PS> ./cd-windows.ps1
|
||||||
📂C:\Windows entered (has 7 files and 42 folders)
|
📂C:\Windows with 7 files and 42 folders entered.
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -13,16 +13,17 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if ($IsLinux -or $IsMacOS) { throw "This script requires a Windows operating system" }
|
||||||
|
|
||||||
$path = Resolve-Path "$env:WINDIR"
|
$path = Resolve-Path "$env:WINDIR"
|
||||||
if (-not(Test-Path "$path" -pathType container)) {
|
if (-not(Test-Path "$path" -pathType container)) { throw "No Windows directory at $path" }
|
||||||
throw "No Windows directory at $path"
|
|
||||||
}
|
|
||||||
Set-Location "$path"
|
Set-Location "$path"
|
||||||
$files = Get-ChildItem $path -attributes !Directory
|
$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)"
|
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ ERROR: $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user