Updated some scripts

This commit is contained in:
Markus Fleschutz 2025-05-29 09:32:06 +02:00
parent 52b42420f7
commit 29a8c968f8
4 changed files with 17 additions and 21 deletions

View File

@ -4,8 +4,8 @@
.DESCRIPTION
This PowerShell script changes the working directory to the user's downloads folder.
.EXAMPLE
PS> ./cd-downloads
📂C:\Users\Markus\Downloads entered (has 0 files and 0 folders)
PS> ./cd-downloads.ps1
📂C:\Users\Markus\Downloads with 0 files and 0 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -15,19 +15,19 @@
try {
if ($IsLinux -or $IsMacOS) {
if (-not(Test-Path "~/Downloads" -pathType container)) {
throw "No 📂Downloads folder in your home directory yet"
throw "No 'Downloads' folder in your home directory yet"
}
$path = Resolve-Path "~/Downloads"
} else {
$path = (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path
if (-not(Test-Path "$path" -pathType container)) {
throw "No downloads folder at 📂$path"
throw "No downloads 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 with $($files.Count) files and $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

View File

@ -4,8 +4,8 @@
.DESCRIPTION
This PowerShell script changes the working directory to the user's music folder.
.EXAMPLE
PS> ./cd-music
📂C:\Users\Markus\Music entered (has 3 folders and 0 files)
PS> ./cd-music.ps1
📂C:\Users\Markus\Music with 3 folders and 0 files entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -15,7 +15,7 @@
try {
if ($IsLinux) {
if (-not(Test-Path "~/Music/" -pathType container)) {
throw "No music folder at ~/Music/"
throw "No 'Music' folder in home directory"
}
$path = Resolve-Path "~/Music"
} else {
@ -25,9 +25,9 @@ try {
}
}
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($folders.Count) folders and $($files.Count) files)"
$files = Get-ChildItem $path -attributes !Directory
"📂$path with $($folders.Count) folders and $($files.Count) files entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the folder for Git repositories.
.EXAMPLE
PS> ./cd-repos.ps1
📂C:\Repos (has 33 subfolders)
📂C:\Repos with 33 folders entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -23,13 +23,11 @@ try {
} elseif (Test-Path "/repositories" -pathType container) { $path = "/repositories"
} elseif (Test-Path "~/source/repos" -pathType container) { $path = "~/source/repos" # Visual Studio default
} elseif (Test-Path "D:/Repos" -pathType container) { $path = "D:/Repos" # second HDD
} else {
throw "No folder found for Git repositories (in home or root directory) - Please create one."
}
} else { throw "Found no folder for Git repositories (in home or root directory) - Please create one." }
$path = Resolve-Path $path
Set-Location "$path"
$subfolders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($subfolders.Count) subfolders)"
$folders = Get-ChildItem $path -attributes Directory
"📂$path with $($folders.Count) folders entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the PowerShell scripts folder.
.EXAMPLE
PS> ./cd-scripts.ps1
📂C:\Repos\PowerShell\scripts entered (has 645 scripts)
📂C:\Repos\PowerShell\scripts with 655 scripts entered.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -14,12 +14,10 @@
try {
$path = Resolve-Path "$PSScriptRoot"
if (-not(Test-Path "$path" -pathType container)) {
throw "No PowerShell scripts folder at 📂$path"
}
if (-not(Test-Path "$path" -pathType container)) { throw "No scripts folder at: $path" }
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory
"📂$path entered (has $($files.Count) scripts)"
"📂$path with $($files.Count) scripts entered."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"