1

Is there a way of extending the answer to this question to include the string " New Folder". e.g. "20221029 New Folder"

Current workaround that I am using in this Registry Key

Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\NewFolderWithDate\command

is

cmd.exe /c powershell New-Item -ItemType Directory -Path ".\$((Get-Date).ToString('yyyyMMdd  New'))"

This works in cmd.exe but with no spaces:

powershell New-Item -ItemType Directory -Path ".\$((Get-Date).ToString('yyyyMMdd'))NewFolder"
akarich73
  • 15
  • 4
  • For me it works this way `powershell -NoProfile -Command "& {New-Item -ItemType Directory -Path """.\$((Get-Date).ToString('yyyyMMdd')) New Folder"""}"` – Olaf Oct 29 '22 at 01:18

1 Answers1

1

Use the following (note that there is no need to call via cmd /c):

powershell "New-Item -ItemType Directory -Path \".\$((Get-Date).ToString('yyyyMMdd  New'))\""
  • Use \" to escape " characters that you want PowerShell to retain as part of the PowerShell command to execute, after command-line parsing - see this answer for more information.

  • Embed the command to pass (to the implied -Command CLI parameter) as a whole in "..." so as to prevent whitespace normalization; that is, without it, the two spaces before New in your command would become one.

mklement0
  • 382,024
  • 64
  • 607
  • 775