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