mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-31 23:45:48 +02:00
Updated cd-music.ps1
This commit is contained in:
parent
e3672038e5
commit
19bcaa9e3d
@ -5,7 +5,7 @@
|
|||||||
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
|
||||||
📂C:\Users\Markus\Music entered (has 0 files and 3 subfolders)
|
📂C:\Users\Markus\Music entered (has 3 folders and 0 files)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -14,17 +14,20 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if ($IsLinux) {
|
if ($IsLinux) {
|
||||||
|
if (-not(Test-Path "~/Music/" -pathType container)) {
|
||||||
|
throw "No music folder at ~/Music/"
|
||||||
|
}
|
||||||
$path = Resolve-Path "~/Music"
|
$path = Resolve-Path "~/Music"
|
||||||
} else {
|
} else {
|
||||||
$path = [Environment]::GetFolderPath('MyMusic')
|
$path = [Environment]::GetFolderPath('MyMusic')
|
||||||
}
|
if (-not(Test-Path "$path" -pathType container)) {
|
||||||
if (-not(Test-Path "$path" -pathType container)) {
|
throw "No music folder at: $path"
|
||||||
throw "No music 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) subfolders)"
|
"📂$path entered (has $($folders.Count) folders and $($files.Count) files)"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user