Create a temporary directory in PowerShell?

前端 未结 8 1724
一生所求
一生所求 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条回答
  •  醉酒成梦
    2021-02-01 15:28

    .NET has had [System.IO.Path]::GetTempFileName() for quite a while; you can use this to generate a file (and the capture the name), then create a folder with the same name after deleting the file.

    $tempfile = [System.IO.Path]::GetTempFileName();
    remove-item $tempfile;
    new-item -type directory -path $tempfile;
    

提交回复
热议问题