From ea112a42bd6b961909095836cf5b9a085a893ae4 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 27 Mar 2025 12:22:40 +0100 Subject: [PATCH] Updated the cd-*.ps1 scripts --- scripts/cd-autostart.ps1 | 4 ++-- scripts/cd-crashdumps.ps1 | 6 +++--- scripts/cd-desktop.ps1 | 12 ++++++------ scripts/cd-docs.ps1 | 4 ++-- scripts/cd-downloads.ps1 | 4 ++-- scripts/cd-dropbox.ps1 | 4 +++- scripts/cd-etc.ps1 | 4 ++-- scripts/cd-fonts.ps1 | 4 ++-- scripts/cd-home.ps1 | 4 ++-- scripts/cd-jenkins.ps1 | 6 ++++-- scripts/cd-logs.ps1 | 2 +- scripts/cd-music.ps1 | 8 ++++---- scripts/cd-nextcloud.ps1 | 10 +++++++--- scripts/cd-onedrive.ps1 | 10 +++++++--- scripts/cd-pics.ps1 | 10 ++++++---- scripts/cd-public.ps1 | 12 ++++++++---- scripts/cd-recent.ps1 | 8 +++++--- scripts/cd-recycle-bin.ps1 | 12 ++++++++---- scripts/cd-root.ps1 | 2 +- scripts/cd-screenshots.ps1 | 2 +- scripts/cd-scripts.ps1 | 8 +++++--- scripts/cd-ssh.ps1 | 9 ++++++--- scripts/cd-temp.ps1 | 12 ++++++++---- scripts/cd-templates.ps1 | 12 ++++++++---- scripts/cd-trash.ps1 | 12 ++++++++---- scripts/cd-users.ps1 | 12 ++++++++---- scripts/cd-videos.ps1 | 12 ++++++++---- scripts/cd-windows.ps1 | 12 ++++++++---- 28 files changed, 135 insertions(+), 82 deletions(-) diff --git a/scripts/cd-autostart.ps1 b/scripts/cd-autostart.ps1 index 96115f24..6f6cbd7e 100755 --- a/scripts/cd-autostart.ps1 +++ b/scripts/cd-autostart.ps1 @@ -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 } diff --git a/scripts/cd-crashdumps.ps1 b/scripts/cd-crashdumps.ps1 index b9734e34..13c63da6 100755 --- a/scripts/cd-crashdumps.ps1 +++ b/scripts/cd-crashdumps.ps1 @@ -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 } diff --git a/scripts/cd-desktop.ps1 b/scripts/cd-desktop.ps1 index 90c2fcd5..e36c9a15 100755 --- a/scripts/cd-desktop.ps1 +++ b/scripts/cd-desktop.ps1 @@ -18,13 +18,13 @@ try { } else { $path = [Environment]::GetFolderPath('DesktopDirectory') } - if (Test-Path "$path" -pathType container) { - Set-Location "$path" - "📂$path" - exit 0 # success + if (-not(Test-Path "$path" -pathType container)) { + throw "No desktop folder at 📂$path" } - throw "User's desktop folder at 📂$path doesn't exist (yet)" + Set-Location "$path" + "📂$path" + exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ Error: $($Error[0])" exit 1 } diff --git a/scripts/cd-docs.ps1 b/scripts/cd-docs.ps1 index efbdab17..dfa88a1a 100755 --- a/scripts/cd-docs.ps1 +++ b/scripts/cd-docs.ps1 @@ -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 } diff --git a/scripts/cd-downloads.ps1 b/scripts/cd-downloads.ps1 index bb697e3c..a3a44f76 100755 --- a/scripts/cd-downloads.ps1 +++ b/scripts/cd-downloads.ps1 @@ -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 } diff --git a/scripts/cd-dropbox.ps1 b/scripts/cd-dropbox.ps1 index 15c7c981..8d0cab2d 100755 --- a/scripts/cd-dropbox.ps1 +++ b/scripts/cd-dropbox.ps1 @@ -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 diff --git a/scripts/cd-etc.ps1 b/scripts/cd-etc.ps1 index 0eaff8a0..b2886dbb 100755 --- a/scripts/cd-etc.ps1 +++ b/scripts/cd-etc.ps1 @@ -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 } diff --git a/scripts/cd-fonts.ps1 b/scripts/cd-fonts.ps1 index d755eca8..e6ef247f 100755 --- a/scripts/cd-fonts.ps1 +++ b/scripts/cd-fonts.ps1 @@ -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 } diff --git a/scripts/cd-home.ps1 b/scripts/cd-home.ps1 index 18a764b3..6f56b4cd 100755 --- a/scripts/cd-home.ps1 +++ b/scripts/cd-home.ps1 @@ -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 } diff --git a/scripts/cd-jenkins.ps1 b/scripts/cd-jenkins.ps1 index 9e91593a..3514eb5c 100755 --- a/scripts/cd-jenkins.ps1 +++ b/scripts/cd-jenkins.ps1 @@ -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])" diff --git a/scripts/cd-logs.ps1 b/scripts/cd-logs.ps1 index 20caf9fa..1f4cc98d 100755 --- a/scripts/cd-logs.ps1 +++ b/scripts/cd-logs.ps1 @@ -24,6 +24,6 @@ try { "📂$path" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ Error: $($Error[0])" exit 1 } diff --git a/scripts/cd-music.ps1 b/scripts/cd-music.ps1 index 6760f744..15241901 100755 --- a/scripts/cd-music.ps1 +++ b/scripts/cd-music.ps1 @@ -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 } diff --git a/scripts/cd-nextcloud.ps1 b/scripts/cd-nextcloud.ps1 index b7c64d11..d405cf72 100755 --- a/scripts/cd-nextcloud.ps1 +++ b/scripts/cd-nextcloud.ps1 @@ -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])" diff --git a/scripts/cd-onedrive.ps1 b/scripts/cd-onedrive.ps1 index b84c3102..af66cb4f 100755 --- a/scripts/cd-onedrive.ps1 +++ b/scripts/cd-onedrive.ps1 @@ -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])" diff --git a/scripts/cd-pics.ps1 b/scripts/cd-pics.ps1 index 1ce3959e..2a760438 100755 --- a/scripts/cd-pics.ps1 +++ b/scripts/cd-pics.ps1 @@ -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 } diff --git a/scripts/cd-public.ps1 b/scripts/cd-public.ps1 index 4876174f..262e8434 100755 --- a/scripts/cd-public.ps1 +++ b/scripts/cd-public.ps1 @@ -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 } diff --git a/scripts/cd-recent.ps1 b/scripts/cd-recent.ps1 index 60270307..84093498 100755 --- a/scripts/cd-recent.ps1 +++ b/scripts/cd-recent.ps1 @@ -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])" diff --git a/scripts/cd-recycle-bin.ps1 b/scripts/cd-recycle-bin.ps1 index eecb1c24..2f301e50 100755 --- a/scripts/cd-recycle-bin.ps1 +++ b/scripts/cd-recycle-bin.ps1 @@ -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 } diff --git a/scripts/cd-root.ps1 b/scripts/cd-root.ps1 index db402b47..4a09d4fa 100755 --- a/scripts/cd-root.ps1 +++ b/scripts/cd-root.ps1 @@ -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 } diff --git a/scripts/cd-screenshots.ps1 b/scripts/cd-screenshots.ps1 index 8bd1f885..809e6e0a 100755 --- a/scripts/cd-screenshots.ps1 +++ b/scripts/cd-screenshots.ps1 @@ -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 } diff --git a/scripts/cd-scripts.ps1 b/scripts/cd-scripts.ps1 index 0f7310b7..c7fb9a27 100755 --- a/scripts/cd-scripts.ps1 +++ b/scripts/cd-scripts.ps1 @@ -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 } diff --git a/scripts/cd-ssh.ps1 b/scripts/cd-ssh.ps1 index bde81a09..d0e33c68 100755 --- a/scripts/cd-ssh.ps1 +++ b/scripts/cd-ssh.ps1 @@ -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])" diff --git a/scripts/cd-temp.ps1 b/scripts/cd-temp.ps1 index 6403c761..b518c4e9 100755 --- a/scripts/cd-temp.ps1 +++ b/scripts/cd-temp.ps1 @@ -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 } diff --git a/scripts/cd-templates.ps1 b/scripts/cd-templates.ps1 index 8988b56a..bc029401 100755 --- a/scripts/cd-templates.ps1 +++ b/scripts/cd-templates.ps1 @@ -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 } diff --git a/scripts/cd-trash.ps1 b/scripts/cd-trash.ps1 index fa32e4a4..5289ecb4 100755 --- a/scripts/cd-trash.ps1 +++ b/scripts/cd-trash.ps1 @@ -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 } diff --git a/scripts/cd-users.ps1 b/scripts/cd-users.ps1 index 338fb9ee..861ddcb3 100755 --- a/scripts/cd-users.ps1 +++ b/scripts/cd-users.ps1 @@ -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 } diff --git a/scripts/cd-videos.ps1 b/scripts/cd-videos.ps1 index 8cf4db75..90be1ab7 100755 --- a/scripts/cd-videos.ps1 +++ b/scripts/cd-videos.ps1 @@ -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 } diff --git a/scripts/cd-windows.ps1 b/scripts/cd-windows.ps1 index 8f6cfe96..3b3d4e87 100755 --- a/scripts/cd-windows.ps1 +++ b/scripts/cd-windows.ps1 @@ -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 }