Updated the cd-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2025-03-27 12:22:40 +01:00
parent 37fb994ed5
commit ea112a42bd
28 changed files with 135 additions and 82 deletions

View File

@ -15,12 +15,12 @@
try {
$path = Resolve-Path "~/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"
if (-not(Test-Path "$path" -pathType container)) {
throw "Autostart folder at 📂$path doesn't exist (yet)"
throw "No autostart folder at 📂$path"
}
Set-Location "$path"
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -16,16 +16,16 @@ try {
if ($IsLinux) { throw "Sorry, Windows only" }
[string]$path = Resolve-Path -Path "~"
if (!(Test-Path "$path" -pathType container)) { throw "Home directory at $path doesn't exist (yet)" }
if (!(Test-Path "$path" -pathType container)) { throw "No home directory at $path" }
$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 "No crashdumps folder at $path" }
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])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -18,13 +18,13 @@ try {
} else {
$path = [Environment]::GetFolderPath('DesktopDirectory')
}
if (Test-Path "$path" -pathType container) {
if (-not(Test-Path "$path" -pathType container)) {
throw "No desktop folder at 📂$path"
}
Set-Location "$path"
"📂$path"
exit 0 # success
}
throw "User's desktop folder at 📂$path doesn't exist (yet)"
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -19,7 +19,7 @@ try {
$path = [Environment]::GetFolderPath('MyDocuments')
}
if (-not(Test-Path "$path" -pathType container)) {
throw "Documents folder at 📂$path doesn't exist (yet)"
throw "No documents folder at 📂$path"
}
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
@ -27,6 +27,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -19,7 +19,7 @@ try {
$path = (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path
}
if (-not(Test-Path "$path" -pathType container)) {
throw "User's downloads folder at 📂$path doesn't exist (yet)"
throw "No downloads folder at 📂$path"
}
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
@ -27,6 +27,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -14,7 +14,9 @@
try {
$path = Resolve-Path "~/Dropbox"
if (-not(Test-Path "$path" -pathType container)) { throw "No Dropbox folder at 📂$path - is Dropbox installed?" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No Dropbox folder at 📂$path - is Dropbox installed?"
}
Set-Location "$path"
"📂$path"
exit 0 # success

View File

@ -19,12 +19,12 @@ try {
$path = Resolve-Path "$env:WINDIR\System32\drivers\etc"
}
if (-not(Test-Path "$path" -pathType container)) {
throw "/etc directory at 📂$path doesn't exist (yet)"
throw "No /etc directory at 📂$path"
}
Set-Location "$path"
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -15,12 +15,12 @@
try {
$path = [Environment]::GetFolderPath('Fonts')
if (-not(Test-Path "$path" -pathType container)) {
throw "Fonts folder at 📂$path doesn't exist (yet)"
throw "No fonts folder at 📂$path"
}
Set-Location "$path"
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -14,13 +14,13 @@
try {
$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 "No home directory at $path" }
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])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the Jenkins home directory.
.EXAMPLE
PS> ./cd-jenkins
📂C:\Users\Markus\.jenkins
📂C:\Users\Markus\.jenkins entered (has 2 files and 21 folders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -21,7 +21,9 @@ try {
throw "No Jenkins home directory found - is Jenkins installed?"
}
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: $($Error[0])"

View File

@ -24,6 +24,6 @@ try {
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

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 entered (has 0 files and 3 folders)
📂C:\Users\Markus\Music entered (has 0 files and 3 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -19,14 +19,14 @@ try {
$path = [Environment]::GetFolderPath('MyMusic')
}
if (-not(Test-Path "$path" -pathType container)) {
throw "User's music folder at 📂$path doesn't exist (yet)"
throw "No music folder at 📂$path"
}
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)"
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's NextCloud folder.
.EXAMPLE
PS> ./cd-nextcloud
📂C:\Users\Markus\NextCloud
📂C:\Users\Markus\NextCloud entered (has 2 files and 3 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -14,9 +14,13 @@
try {
$path = Resolve-Path "~/NextCloud"
if (-not(Test-Path "$path" -pathType container)) { throw "No NextCloud folder at 📂$path - is NextCloud installed?" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No NextCloud folder at $path - is NextCloud installed?"
}
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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's OneDrive folder.
.EXAMPLE
PS> ./cd-onedrive
📂C:\Users\Markus\OneDrive
📂C:\Users\Markus\OneDrive entered (has 2 files and 3 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -14,9 +14,13 @@
try {
$path = Resolve-Path "~/OneDrive"
if (-not(Test-Path "$path" -pathType container)) { throw "No OneDrive folder at 📂$path - is OneDrive installed?" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No OneDrive folder at $path - is OneDrive installed?"
}
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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

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 entered (has 7 files and 0 folders)
📂C:\Users\Markus\Pictures entered (has 7 files and 0 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -18,13 +18,15 @@ try {
} else {
$path = [Environment]::GetFolderPath('MyPictures')
}
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No pictures folder at $path"
}
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)"
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the Public folder.
.EXAMPLE
PS> ./cd-public
📂C:\Users\Public
📂C:\Users\Public entered (has 2 files and 3 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -18,11 +18,15 @@ try {
} else {
$path = Resolve-Path "~/../Public"
}
if (-not(Test-Path "$path" -pathType container)) { throw "Public folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No public folder at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the 'recent' folder.
.EXAMPLE
PS> ./cd-recent
📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent
📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent entered (has 2 files and 3 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -15,10 +15,12 @@
try {
$path = [Environment]::GetFolderPath('Recent')
if (-not(Test-Path "$path" -pathType container)) {
throw "Recent folder at 📂$path doesn't exist (yet)"
throw "No recent folder at $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) subfolders)"
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 recycle bin folder.
.EXAMPLE
PS> ./cd-recycle-bin
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 entered (has 2 files and 0 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -24,11 +24,15 @@ try {
} else {
$path = "C:\`$Recycle.Bin\$(GetCurrentUserSID)"
}
if (-not(Test-Path "$path" -pathType container)) { throw "Recycle bin folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No recycle bin folder at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -20,6 +20,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -33,6 +33,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -14,12 +14,14 @@
try {
$path = Resolve-Path "$PSScriptRoot"
if (-not(Test-Path "$path" -pathType container)) { throw "PowerShell scripts folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No PowerShell scripts folder at 📂$path"
}
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
"📂$path entered (has $($files.Count) scripts)"
Set-Location "$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

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

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the temporary folder.
.EXAMPLE
PS> ./cd-temp
📂C:\Users\Markus\AppData\Local\Temp
📂C:\Users\Markus\AppData\Local\Temp (has 2 files and 3 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -21,11 +21,15 @@ function GetTempDir {
try {
$path = GetTempDir
if (-not(Test-Path "$path" -pathType container)) { throw "Temporary folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) { throw
"No temporary folder at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the templates folder.
.EXAMPLE
PS> ./cd-templates
📂/home/Markus/Templates
📂/home/Markus/Templates entered (has 3 files and 0 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -18,11 +18,15 @@ try {
} else {
$path = [Environment]::GetFolderPath('Templates')
}
if (-not(Test-Path "$path" -pathType container)) { throw "Templates folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No templates folder at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's trash folder.
.EXAMPLE
PS> ./cd-trash
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 entered (has 4 files and 0 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -24,11 +24,15 @@ try {
} else {
$path = "C:\`$Recycle.Bin\$(GetCurrentUserSID)"
}
if (-not(Test-Path "$path" -pathType container)) { throw "Trash folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No trash folder at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the users directory.
.EXAMPLE
PS> ./cd-users
📂C:\Users
📂C:\Users entered (has 0 files and 4 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -14,11 +14,15 @@
try {
$path = Resolve-Path "~/.."
if (-not(Test-Path "$path" -pathType container)) { throw "Users directory at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No users directory at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's videos folder.
.EXAMPLE
PS> ./cd-videos
📂C:\Users\Markus\Videos
📂C:\Users\Markus\Videos entered (has 3 files and 0 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -18,11 +18,15 @@ try {
} else {
$path = [Environment]::GetFolderPath('MyVideos')
}
if (-not(Test-Path "$path" -pathType container)) { throw "Videos folder at 📂$path doesn't exist (yet)" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No videos folder at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the Windows directory.
.EXAMPLE
PS> ./cd-windows
📂C:\Windows
📂C:\Windows entered (has 7 files and 42 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -14,11 +14,15 @@
try {
$path = Resolve-Path "$env:WINDIR"
if (-not(Test-Path "$path" -pathType container)) { throw "Windows directory at 📂$path doesn't exist" }
if (-not(Test-Path "$path" -pathType container)) {
throw "No Windows directory at $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) subfolders)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}