Improved some cd-*.ps1 scripts

This commit is contained in:
Markus Fleschutz
2025-04-23 13:22:05 +02:00
parent 257c2c3d82
commit c35fcd8ea0
8 changed files with 39 additions and 25 deletions

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's Dropbox folder.
.EXAMPLE
PS> ./cd-dropbox
📂C:\Users\Markus\Dropbox
📂C:\Users\Markus\Dropbox (has 2 files and 4 subfolders)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -13,12 +13,14 @@
#>
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 "~/Dropbox" -pathType container)) {
throw "No 📂Dropbox folder in your home directory - is Dropbox installed?"
}
$path = Resolve-Path "~/Dropbox"
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])"