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. 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 .EXAMPLE
PS> ./cd-crashdumps PS> ./cd-crashdumps
📂C:\Users\Markus\AppData\Local\CrashDumps 📂C:\Users\Markus\AppData\Local\CrashDumps entered (has 3 files and 0 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -21,7 +21,9 @@ try {
$path += "\AppData\Local\CrashDumps" $path += "\AppData\Local\CrashDumps"
if (!(Test-Path "$path" -pathType container)) { throw "Crashdumps directory at $path doesn't exist (yet)" } if (!(Test-Path "$path" -pathType container)) { throw "Crashdumps directory at $path doesn't exist (yet)" }
Set-Location "$Path" 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the documents folder. This PowerShell script changes the working directory to the documents folder.
.EXAMPLE .EXAMPLE
PS> ./cd-docs PS> ./cd-docs
📂C:\Users\Markus\Documents 📂C:\Users\Markus\Documents entered (has 3 files and 0 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -22,7 +22,9 @@ try {
throw "Documents folder at 📂$path doesn't exist (yet)" throw "Documents folder at 📂$path doesn't exist (yet)"
} }
Set-Location "$path" 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ 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. This PowerShell script changes the working directory to the user's downloads folder.
.EXAMPLE .EXAMPLE
PS> ./cd-downloads PS> ./cd-downloads
📂C:\Users\Markus\Downloads 📂C:\Users\Markus\Downloads entered (has 0 files and 0 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -24,7 +24,7 @@ try {
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 (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ 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. This PowerShell script changes the working directory to the user's home directory.
.EXAMPLE .EXAMPLE
PS> ./cd-home.ps1 PS> ./cd-home.ps1
📂C:\Users\Markus 📂C:\Users\Markus entered (has 4 files and 7 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -16,7 +16,9 @@ try {
$path = Resolve-Path "~" $path = Resolve-Path "~"
if (-not(Test-Path "$path" -pathType container)) { throw "Home folder at $path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) { throw "Home folder at $path doesn't exist (yet)" }
Set-Location "$path" 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ 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. This PowerShell script changes the working directory to the user's music folder.
.EXAMPLE .EXAMPLE
PS> ./cd-music PS> ./cd-music
📂C:\Users\Markus\Music 📂C:\Users\Markus\Music entered (has 0 files and 3 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -18,12 +18,14 @@ try {
} else { } else {
$path = [Environment]::GetFolderPath('MyMusic') $path = [Environment]::GetFolderPath('MyMusic')
} }
if (Test-Path "$path" -pathType container) { if (-not(Test-Path "$path" -pathType container)) {
Set-Location "$path"
"📂$path"
exit 0 # success
}
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 { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's pictures folder. This PowerShell script changes the working directory to the user's pictures folder.
.EXAMPLE .EXAMPLE
PS> ./cd-pics PS> ./cd-pics
📂C:\Users\Markus\Pictures 📂C:\Users\Markus\Pictures entered (has 7 files and 0 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -20,7 +20,9 @@ try {
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at 📂$path doesn't exist (yet)" }
Set-Location "$path" 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ 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). This PowerShell script changes the current working directory to the root directory (C:\ on Windows).
.EXAMPLE .EXAMPLE
PS> ./cd-root PS> ./cd-root
📂C:\ 📂C:\ entered (has 0 files and 7 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -15,7 +15,9 @@
try { try {
if ($IsLinux) { $path = "/" } else { $path = "C:\" } if ($IsLinux) { $path = "/" } else { $path = "C:\" }
Set-Location "$path" 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ 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. This PowerShell script changes the working directory to the user's screenshots folder.
.EXAMPLE .EXAMPLE
PS> ./cd-screenshots PS> ./cd-screenshots
📂C:\Users\Markus\Pictures\Screenshots 📂C:\Users\Markus\Pictures\Screenshots (has 7 files and 0 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -28,7 +28,9 @@ function GetScreenshotsFolder {
try { try {
$path = GetScreenshotsFolder $path = GetScreenshotsFolder
Set-Location "$path" 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"