-
-
Notifications
You must be signed in to change notification settings - Fork 437
/
Copy pathcd-screenshots.ps1
executable file
·36 lines (34 loc) · 1.11 KB
/
cd-screenshots.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<#
.SYNOPSIS
Sets the working directory to the user's screenshots folder
.DESCRIPTION
This PowerShell script changes the working directory to the user's screenshots folder.
.EXAMPLE
PS> ./cd-screenshots
📂C:\Users\Markus\Pictures\Screenshots
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function GetScreenshotsFolder {
if ($IsLinux) {
$path = "~/Pictures"
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at $path doesn't exist (yet)" }
if (Test-Path "$path/Screenshots" -pathType container) { $path = "$path/Screenshots" }
} else {
$path = [Environment]::GetFolderPath('MyPictures')
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at $path doesn't exist (yet)" }
if (Test-Path "$path\Screenshots" -pathType container) { $path = "$path\Screenshots" }
}
return $path
}
try {
$path = GetScreenshotsFolder
Set-Location "$path"
"📂$path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}