Create a temporary directory in PowerShell?

前端 未结 8 1818
一生所求
一生所求 2021-02-01 14:36

PowerShell 5 introduces the New-TemporaryFile cmdlet, which is handy. How can I do the same thing but instead of a file create a directory? Is there a New-TemporaryDirec

8条回答
  •  Happy的楠姐
    2021-02-01 15:22

    I also love one-liners, and I'm begging for a downvote here. All I ask is that you put my own vague negative feelings about this into words.

    New-TemporaryFile | %{ rm $_; mkdir $_ }
    

    Depending on the type of purist you are, you can do %{ mkdir $_-d }, leaving placeholder to avoid collisions.

    And it's reasonable to stand on Join-Path $env:TEMP $(New-Guid) | %{ mkdir $_ } also.

提交回复
热议问题