mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-08 17:28:18 +02:00
Add GetTempDir function
This commit is contained in:
parent
2881994f5e
commit
41f8c9d5cd
@ -12,8 +12,13 @@
|
|||||||
Author: Markus Fleschutz · License: CC0
|
Author: Markus Fleschutz · License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function GetTempDir {
|
||||||
|
if ($IsLinux) { return "/tmp" }
|
||||||
|
return "$env:TEMP"
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$TargetDir = resolve-path "$env:TEMP"
|
$TargetDir = resolve-path GetTempDir
|
||||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||||
throw "Temporary folder at 📂$TargetDir doesn't exist (yet)"
|
throw "Temporary folder at 📂$TargetDir doesn't exist (yet)"
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@
|
|||||||
|
|
||||||
param([string]$text = "")
|
param([string]$text = "")
|
||||||
|
|
||||||
|
function GetTempDir {
|
||||||
|
if ($IsLinux) { return "/tmp" }
|
||||||
|
return "$env:TEMP"
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# print reply on the console:
|
# print reply on the console:
|
||||||
" ← $text"
|
" ← $text"
|
||||||
@ -29,7 +34,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# remember last reply:
|
# remember last reply:
|
||||||
"$text" > "$env:TEMP/last_reply.txt"
|
"$text" > "$(GetTempDir)/last_reply_given.txt"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
@ -11,8 +11,13 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
function GetTempDir {
|
||||||
|
if ($IsLinux) { return "/tmp" }
|
||||||
|
return "$env:TEMP"
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$TargetDir = resolve-path "$env:TEMP"
|
$TargetDir = resolve-path GetTempDir
|
||||||
if (-not(test-path "$TargetDir" -pathType container)) {
|
if (-not(test-path "$TargetDir" -pathType container)) {
|
||||||
throw "Temporary folder at 📂$TargetDir doesn't exist (yet)"
|
throw "Temporary folder at 📂$TargetDir doesn't exist (yet)"
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,14 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
if (test-path "$env:TEMP/last_reply.txt" -pathType leaf) {
|
function GetTempDir {
|
||||||
|
if ($IsLinux) { return "/tmp" }
|
||||||
|
return "$env:TEMP"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test-path "$(GetTempDir)/last_reply_given.txt" -pathType leaf) {
|
||||||
$Reply = "It was: "
|
$Reply = "It was: "
|
||||||
$Reply += Get-Content "$env:TEMP/.last_reply.txt"
|
$Reply += Get-Content "$(GetTempDir)/last_reply_given.txt"
|
||||||
} else {
|
} else {
|
||||||
$Reply = "Sorry, I can't remember."
|
$Reply = "Sorry, I can't remember."
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user