Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c35fcd8

Browse files
committedApr 23, 2025
Improved some cd-*.ps1 scripts
1 parent 257c2c3 commit c35fcd8

File tree

8 files changed

+39
-25
lines changed

8 files changed

+39
-25
lines changed
 

‎scripts/cd-desktop.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
#>
1414

1515
try {
16-
if ($IsLinux) {
16+
if ($IsLinux -or $IsMacOS) {
17+
if (-not(Test-Path "~/Desktop" -pathType container)) {
18+
throw "No 📂Desktop folder in your home directory yet"
19+
}
1720
$path = Resolve-Path "~/Desktop"
1821
} else {
1922
$path = [Environment]::GetFolderPath('DesktopDirectory')
20-
}
21-
if (-not(Test-Path "$path" -pathType container)) {
22-
throw "No desktop folder at 📂$path"
23+
if (-not(Test-Path "$path" -pathType container)) {
24+
throw "No desktop folder at 📂$path yet"
25+
}
2326
}
2427
Set-Location "$path"
2528
"📂$path"

‎scripts/cd-docs.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
#>
1414

1515
try {
16-
if ($IsLinux) {
16+
if ($IsLinux -or $IsMacOS) {
17+
if (-not(Test-Path "~/Documents" -pathType container)) {
18+
throw "No 📂Documents folder in your home directory yet"
19+
}
1720
$path = Resolve-Path "~/Documents"
1821
} else {
1922
$path = [Environment]::GetFolderPath('MyDocuments')
20-
}
21-
if (-not(Test-Path "$path" -pathType container)) {
22-
throw "No documents folder at 📂$path"
23+
if (-not(Test-Path "$path" -pathType container)) {
24+
throw "No documents folder at 📂$path yet"
25+
}
2326
}
2427
Set-Location "$path"
2528
$files = Get-ChildItem $path -attributes !Directory

‎scripts/cd-downloads.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
try {
1616
if ($IsLinux -or $IsMacOS) {
1717
if (-not(Test-Path "~/Downloads" -pathType container)) {
18-
throw "No downloads folder at ~/Downloads yet"
18+
throw "No 📂Downloads folder in your home directory yet"
1919
}
2020
$path = Resolve-Path "~/Downloads"
2121
} else {

‎scripts/cd-dropbox.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
This PowerShell script changes the working directory to the user's Dropbox folder.
66
.EXAMPLE
77
PS> ./cd-dropbox
8-
📂C:\Users\Markus\Dropbox
8+
📂C:\Users\Markus\Dropbox (has 2 files and 4 subfolders)
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

1515
try {
16-
$path = Resolve-Path "~/Dropbox"
17-
if (-not(Test-Path "$path" -pathType container)) {
18-
throw "No Dropbox folder at 📂$path - is Dropbox installed?"
16+
if (-not(Test-Path "~/Dropbox" -pathType container)) {
17+
throw "No 📂Dropbox folder in your home directory - is Dropbox installed?"
1918
}
19+
$path = Resolve-Path "~/Dropbox"
2020
Set-Location "$path"
21-
"📂$path"
21+
$files = Get-ChildItem $path -attributes !Directory
22+
$folders = Get-ChildItem $path -attributes Directory
23+
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
2224
exit 0 # success
2325
} catch {
2426
"⚠️ Error: $($Error[0])"

‎scripts/cd-etc.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
This PowerShell script changes the working directory to the /etc directory.
66
.EXAMPLE
77
PS> ./cd-etc
8-
📂C:\Windows\System32\drivers\etc
8+
📂C:\Windows\System32\drivers\etc (has 2 files and 3 subfolders)
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

1515
try {
16-
if ($IsLinx) {
16+
if ($IsLinux -or $IsMacOS) {
1717
$path = "/etc"
1818
} else {
1919
$path = Resolve-Path "$env:WINDIR\System32\drivers\etc"
@@ -22,7 +22,9 @@ try {
2222
throw "No /etc directory at 📂$path"
2323
}
2424
Set-Location "$path"
25-
"📂$path"
25+
$files = Get-ChildItem $path -attributes !Directory
26+
$folders = Get-ChildItem $path -attributes Directory
27+
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
2628
exit 0 # success
2729
} catch {
2830
"⚠️ Error: $($Error[0])"

‎scripts/cd-fonts.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This PowerShell script changes the working directory to the fonts folder.
66
.EXAMPLE
77
PS> ./cd-fonts
8-
📂C:\Windows\Fonts
8+
📂C:\Windows\Fonts (has 2 file and 3 subfolders)
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
@@ -18,7 +18,9 @@ try {
1818
throw "No fonts folder at 📂$path"
1919
}
2020
Set-Location "$path"
21-
"📂$path"
21+
$files = Get-ChildItem $path -attributes !Directory
22+
$folders = Get-ChildItem $path -attributes Directory
23+
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
2224
exit 0 # success
2325
} catch {
2426
"⚠️ Error: $($Error[0])"

‎scripts/cd-home.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
This PowerShell script changes the working directory to the user's home directory.
66
.EXAMPLE
77
PS> ./cd-home.ps1
8-
📂C:\Users\Markus entered (has 4 files and 7 folders)
8+
📂C:\Users\Markus entered (has 4 files and 7 subfolders)
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

1515
try {
16+
if (-not(Test-Path "~" -pathType container)) { throw "No home directory at $path" }
1617
$path = Resolve-Path "~"
17-
if (-not(Test-Path "$path" -pathType container)) { throw "No home directory at $path" }
1818
Set-Location "$path"
1919
$files = Get-ChildItem $path -attributes !Directory
2020
$folders = Get-ChildItem $path -attributes Directory
21-
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
21+
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
2222
exit 0 # success
2323
} catch {
2424
"⚠️ Error: $($Error[0])"

‎scripts/cd-logs.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
This PowerShell script changes the current working directory to the logs directory.
66
.EXAMPLE
77
PS> ./cd-logs
8-
📂/var/logs
8+
📂/var/logs entered (has 3 files and 2 subfolders)
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

1515
function GetLogsDir {
16-
if ($IsLinux) { return "/var/logs" }
16+
if ($IsLinux -or $IsMacOS) { return "/var/logs" }
1717
$WinDir = [System.Environment]::GetFolderPath('Windows')
1818
return "$WinDir\Logs"
1919
}
2020

2121
try {
2222
$path = GetLogsDir
2323
Set-Location "$path"
24-
"📂$path"
24+
$files = Get-ChildItem $path -attributes !Directory
25+
$folders = Get-ChildItem $path -attributes Directory
26+
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
2527
exit 0 # success
2628
} catch {
2729
"⚠️ Error: $($Error[0])"

0 commit comments

Comments
 (0)
Please sign in to comment.