0

i'm looking for a way to create a temporary directory on my desktop. something like temp#354 or so.

I thought it could go like this: $user/desktop mkdir temp{#}

and the {#} generates a random number? 4-5 digits would be enough.

it should work from win 7 and the powershell, or even better right click do something?

Peter Eberle
  • 1,081
  • 2
  • 8
  • 14
  • You want to create a temp directory on your desktop. If you just needed a temp file (not a directory and not on the desktop) and you wanted to let Windows handle it, you could use PowerShell to do this: `[System.IO.Path]::GetTempFileName()` – Todd Walton Jun 27 '17 at 13:20

1 Answers1

0

Something like this should do:

$tempdir = "temp#" + ("{0:d5}" -f (Get-Random)).Substring(0,5)
New-Item -ItemType Directory -Path "$env:USERPROFILE\Desktop\$tempdir"

If you want to be able to create such a directory in any folder, you could add a Create Temp Directory entry to the folder context menu:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\mktemp]
@="Create Temp Directory"

[HKEY_CLASSES_ROOT\Directory\shell\mktemp\command]
@="\"C:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe\" -Command \"& {New-Item -ItemType Directory -Path ($args[0] + '\\temp#' + (\\\"{0:d5}\\\" -f (Get-Random)).Substring(0,5))}\" %1"

Replace HKEY_CLASSES_ROOT with HKEY_CURRENT_USER\Software\Classes if you want to apply the modification to your user only.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328