akarich73
akarich73

Reputation: 25

Create folder with current date as "yyyyMMdd New Folder" in context menu with cmd.exe

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"

Upvotes: 1

Views: 611

Answers (1)

mklement0
mklement0

Reputation: 437998

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.

Upvotes: 1

Related Questions