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

View File

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

View File

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

View File

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