question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a platform-agnostic way to determine the temp. directory, e.g., via an automatic variable.

See original GitHub issue

Related: #3442 and #4215

The various supported platforms have different native ways to determine the directory in which to store temporary files and directories:

  • Windows:
    • $env:TEMP
  • macOS:
    • $env:TMPDIR
  • Linux:
    • /tmp

Currently, there is no platform-agnostic way to refer to this directory, which is cumbersome.

An automatic variable, say $TEMP, could provide this abstraction.

Environment data

PowerShell Core v6.0.0-beta.3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:67 (36 by maintainers)

github_iconTop GitHub Comments

6reactions
Jaykulcommented, Oct 6, 2018

Short answer: [IO.Path]::GetTempPath() is the ONLY answer.

The idea that we need to protect people from learning about .NET is, frankly, silly. That static method is backwards compatible all the way to Windows PowerShell 1.0 and no matter how many improvements we add in the future, it’s still the one and only correct answer to the original question today (over a year after it was asked and answered).

However, I like the idea that we should make this easier in the future, even though anything we come up with won’t be reliably usable for years, because PowerShell Core 6 and 6.1 have already shipped without it.

Of all the ideas expressed above, the only idea I like (and I love it) is the idea of creating a Temp: drive and pointing it at (a new folder named after a GUID and/or date in) the location returned by [IO.Path]::GetTempPath() (and maybe cleaning it up when PowerShell exits). Creating a Temp drive is something we can easily do in both PowerShell Core and in a compatibility module for already released versions. It’s very unlikely to cause a problem (it’s just a question of whether anyone is likely to have created a Temp: drive) and if it does, fixing it in the script where that problem occurs would be trivial.

Obviously we could also add New-TempDirectory to the New-TempFile command – but that should be done in an external module to start with so that it can be inherently cross-platform and backwards compatible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does VS Code PowerShell terminal map a new drive?
according to this >>> Provide a platform-agnostic way to determine the temp. directory, e.g., via an automatic variable.
Read more >
Temporary folder
In MS-DOS and Microsoft Windows, the temporary directory is set by the environment variable TEMP or TMP. Using the Window API, one can...
Read more >
sys_get_temp_dir - Manual
Returns the path of the directory PHP stores temporary files in by default. Parameters ¶. This function has no parameters. Return Values ¶....
Read more >
これらのパスはプロジェクトの Content ディレクトリに対応してい ...
Example: Give it a Unreal File System path (eg: /Game/Blueprints) and it will load the filtered assets in that directory and return an...
Read more >
Managing software
Managing software. Use software packages to install, update, or remove software on a set of target computers. Use software bundles to specify a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found