PowerShell/scripts/open-temporary-folder.ps1

32 lines
739 B
PowerShell
Raw Normal View History

2023-10-31 12:48:22 +01:00
<#
.SYNOPSIS
Opens the temporary folder
.DESCRIPTION
This script launches the File Explorer showing the temporary folder.
.EXAMPLE
PS> ./open-temporary-folder
.LINK
https://github.com/fleschutz/PowerShell
2022-09-06 21:42:04 +02:00
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2021-12-09 16:36:44 +01:00
function GetTempDir {
2021-12-10 11:51:51 +01:00
if ("$env:TEMP" -ne "") { return "$env:TEMP" }
if ("$env:TMP" -ne "") { return "$env:TMP" }
2021-12-09 16:36:44 +01:00
if ($IsLinux) { return "/tmp" }
2021-12-10 11:51:51 +01:00
return "C:\Temp"
2021-12-09 16:36:44 +01:00
}
try {
2021-12-10 11:51:51 +01:00
$Path = GetTempDir
if (-not(test-path "$Path" -pathType container)) {
throw "Temporary folder at 📂$Path doesn't exist (yet)"
}
2021-12-10 11:51:51 +01:00
& "$PSScriptRoot/open-file-explorer.ps1" "$Path"
exit 0 # success
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}