File tree Expand file tree Collapse file tree 2 files changed +18
-15
lines changed Expand file tree Collapse file tree 2 files changed +18
-15
lines changed Original file line number Diff line number Diff line change 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
1414
1515try {
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 ]) "
Original file line number Diff line number Diff line change 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
1414
1515function 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
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 ]) "
You can’t perform that action at this time.
0 commit comments