Updated some cd-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2025-03-27 09:00:15 +01:00
parent be820bb0cf
commit 37fb994ed5
8 changed files with 34 additions and 20 deletions

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the crash dumps directory (Windows only). Whenever a software crashes and crash dumps are enabled(!) a crash dump file is written. This file helps to identify the reason for the crash.
.EXAMPLE
PS> ./cd-crashdumps
📂C:\Users\Markus\AppData\Local\CrashDumps
📂C:\Users\Markus\AppData\Local\CrashDumps entered (has 3 files and 0 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -21,7 +21,9 @@ try {
$path += "\AppData\Local\CrashDumps"
if (!(Test-Path "$path" -pathType container)) { throw "Crashdumps directory at $path doesn't exist (yet)" }
Set-Location "$Path"
"📂$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the documents folder.
.EXAMPLE
PS> ./cd-docs
📂C:\Users\Markus\Documents
📂C:\Users\Markus\Documents entered (has 3 files and 0 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -22,7 +22,9 @@ try {
throw "Documents folder at 📂$path doesn't exist (yet)"
}
Set-Location "$path"
"📂$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's downloads folder.
.EXAMPLE
PS> ./cd-downloads
📂C:\Users\Markus\Downloads
📂C:\Users\Markus\Downloads entered (has 0 files and 0 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -24,7 +24,7 @@ try {
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path (has $($files.Count) files and $($folders.Count) folders)"
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's home directory.
.EXAMPLE
PS> ./cd-home.ps1
📂C:\Users\Markus
📂C:\Users\Markus entered (has 4 files and 7 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -16,7 +16,9 @@ try {
$path = Resolve-Path "~"
if (-not(Test-Path "$path" -pathType container)) { throw "Home folder at $path doesn't exist (yet)" }
Set-Location "$path"
"📂$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's music folder.
.EXAMPLE
PS> ./cd-music
📂C:\Users\Markus\Music
📂C:\Users\Markus\Music entered (has 0 files and 3 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -18,12 +18,14 @@ try {
} else {
$path = [Environment]::GetFolderPath('MyMusic')
}
if (Test-Path "$path" -pathType container) {
Set-Location "$path"
"📂$path"
exit 0 # success
if (-not(Test-Path "$path" -pathType container)) {
throw "User's music folder at 📂$path doesn't exist (yet)"
}
throw "User's music folder at 📂$path doesn't exist (yet)"
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's pictures folder.
.EXAMPLE
PS> ./cd-pics
📂C:\Users\Markus\Pictures
📂C:\Users\Markus\Pictures entered (has 7 files and 0 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -20,7 +20,9 @@ try {
}
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at 📂$path doesn't exist (yet)" }
Set-Location "$path"
"📂$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the current working directory to the root directory (C:\ on Windows).
.EXAMPLE
PS> ./cd-root
📂C:\
📂C:\ entered (has 0 files and 7 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -15,7 +15,9 @@
try {
if ($IsLinux) { $path = "/" } else { $path = "C:\" }
Set-Location "$path"
"📂$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's screenshots folder.
.EXAMPLE
PS> ./cd-screenshots
📂C:\Users\Markus\Pictures\Screenshots
📂C:\Users\Markus\Pictures\Screenshots (has 7 files and 0 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -28,7 +28,9 @@ function GetScreenshotsFolder {
try {
$path = GetScreenshotsFolder
Set-Location "$path"
"📂$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"