From 5ad6815ebac87de05bdca9f259d4234bc47757e6 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Fri, 30 May 2025 10:44:57 +0200 Subject: [PATCH] Updated cd-public.ps1 and cd-screenshots.ps1 --- scripts/cd-public.ps1 | 19 +++++++++++-------- scripts/cd-screenshots.ps1 | 14 +++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/scripts/cd-public.ps1 b/scripts/cd-public.ps1 index 262e8434..80f6b3bb 100755 --- a/scripts/cd-public.ps1 +++ b/scripts/cd-public.ps1 @@ -1,11 +1,11 @@ <# .SYNOPSIS - Sets the working directory to the Public folder + Sets the working dir to the Public folder .DESCRIPTION - This PowerShell script changes the working directory to the Public folder. + This PowerShell script sets the current working directory to the Public folder. .EXAMPLE - PS> ./cd-public - 📂C:\Users\Public entered (has 2 files and 3 subfolders) + PS> ./cd-public.ps1 + 📂C:\Users\Public with 2 files and 3 folders entered. .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -14,17 +14,20 @@ try { if ($IsLinux) { + if (-not(Test-Path "~/Public" -pathType container)) { + throw "No 'Public' folder in your home directory yet" + } $path = Resolve-Path "~/Public" } else { + if (-not(Test-Path "~/../Public" -pathType container)) { + throw "No 'Public' folder yet" + } $path = Resolve-Path "~/../Public" } - if (-not(Test-Path "$path" -pathType container)) { - throw "No public 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) subfolders)" + "📂$path with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { "⚠️ Error: $($Error[0])" diff --git a/scripts/cd-screenshots.ps1 b/scripts/cd-screenshots.ps1 index 809e6e0a..b73184be 100755 --- a/scripts/cd-screenshots.ps1 +++ b/scripts/cd-screenshots.ps1 @@ -1,11 +1,11 @@ <# .SYNOPSIS - Sets the working directory to the user's screenshots folder + Sets the working dir to the user's screenshots folder .DESCRIPTION - This PowerShell script changes the working directory to the user's screenshots folder. + This PowerShell script sets the current working directory to the user's screenshots folder. .EXAMPLE - PS> ./cd-screenshots - 📂C:\Users\Markus\Pictures\Screenshots (has 7 files and 0 folders) + PS> ./cd-screenshots.ps1 + 📂C:\Users\Markus\Pictures\Screenshots with 7 files and 0 folders entered. .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -14,12 +14,12 @@ function GetScreenshotsFolder { if ($IsLinux) { + if (-not(Test-Path "~/Pictures" -pathType container)) { throw "No 'Pictures' folder in your home directory yet" } $path = "~/Pictures" - if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at $path doesn't exist (yet)" } if (Test-Path "$path/Screenshots" -pathType container) { $path = "$path/Screenshots" } } 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" } if (Test-Path "$path\Screenshots" -pathType container) { $path = "$path\Screenshots" } } return $path @@ -30,7 +30,7 @@ try { 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 with $($files.Count) files and $($folders.Count) folders entered." exit 0 # success } catch { "⚠️ Error: $($Error[0])"