Skip to content

Commit 5ad6815

Browse files
author
Markus Fleschutz
committed
Updated cd-public.ps1 and cd-screenshots.ps1
1 parent de29c35 commit 5ad6815

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

scripts/cd-public.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<#
22
.SYNOPSIS
3-
Sets the working directory to the Public folder
3+
Sets the working dir to the Public folder
44
.DESCRIPTION
5-
This PowerShell script changes the working directory to the Public folder.
5+
This PowerShell script sets the current working directory to the Public folder.
66
.EXAMPLE
7-
PS> ./cd-public
8-
📂C:\Users\Public entered (has 2 files and 3 subfolders)
7+
PS> ./cd-public.ps1
8+
📂C:\Users\Public with 2 files and 3 folders entered.
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
@@ -14,17 +14,20 @@
1414

1515
try {
1616
if ($IsLinux) {
17+
if (-not(Test-Path "~/Public" -pathType container)) {
18+
throw "No 'Public' folder in your home directory yet"
19+
}
1720
$path = Resolve-Path "~/Public"
1821
} else {
22+
if (-not(Test-Path "~/../Public" -pathType container)) {
23+
throw "No 'Public' folder yet"
24+
}
1925
$path = Resolve-Path "~/../Public"
2026
}
21-
if (-not(Test-Path "$path" -pathType container)) {
22-
throw "No public folder at $path"
23-
}
2427
Set-Location "$path"
2528
$files = Get-ChildItem $path -attributes !Directory
2629
$folders = Get-ChildItem $path -attributes Directory
27-
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
30+
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
2831
exit 0 # success
2932
} catch {
3033
"⚠️ Error: $($Error[0])"

scripts/cd-screenshots.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<#
22
.SYNOPSIS
3-
Sets the working directory to the user's screenshots folder
3+
Sets the working dir to the user's screenshots folder
44
.DESCRIPTION
5-
This PowerShell script changes the working directory to the user's screenshots folder.
5+
This PowerShell script sets the current working directory to the user's screenshots folder.
66
.EXAMPLE
7-
PS> ./cd-screenshots
8-
📂C:\Users\Markus\Pictures\Screenshots (has 7 files and 0 folders)
7+
PS> ./cd-screenshots.ps1
8+
📂C:\Users\Markus\Pictures\Screenshots with 7 files and 0 folders entered.
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
@@ -14,12 +14,12 @@
1414

1515
function GetScreenshotsFolder {
1616
if ($IsLinux) {
17+
if (-not(Test-Path "~/Pictures" -pathType container)) { throw "No 'Pictures' folder in your home directory yet" }
1718
$path = "~/Pictures"
18-
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at $path doesn't exist (yet)" }
1919
if (Test-Path "$path/Screenshots" -pathType container) { $path = "$path/Screenshots" }
2020
} else {
2121
$path = [Environment]::GetFolderPath('MyPictures')
22-
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at $path doesn't exist (yet)" }
22+
if (-not(Test-Path "$path" -pathType container)) { throw "No pictures folder at: $path" }
2323
if (Test-Path "$path\Screenshots" -pathType container) { $path = "$path\Screenshots" }
2424
}
2525
return $path
@@ -30,7 +30,7 @@ try {
3030
Set-Location "$path"
3131
$files = Get-ChildItem $path -attributes !Directory
3232
$folders = Get-ChildItem $path -attributes Directory
33-
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
33+
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
3434
exit 0 # success
3535
} catch {
3636
"⚠️ Error: $($Error[0])"

0 commit comments

Comments
 (0)