To get the current date in the Windows command prompt, use the following:
date /t
To rename a file with the current date, you'll need to use the for
construct to capture the output of the date
command and pass it to ren
:
for /f "useback delims=" %x in (`date /t`) do ren oldfile.foo %x
Note, however, that the output of date
can, depending on your regional settings, contain symbols that cannot be used in a filename, for instance the slash (/
). If so, you have two options:
Format the date such that it is suitable for use in a filename; see this post at Stack Overflow.
Use PowerShell instead. The following should do the trick:
Rename-Item oldfile.foo (Get-Date -Format yyyy-MM-dd)
That example uses the ISO date format. See Formatting Dates and Times for more information.
To add a new context menu entry to all files, do the following:
Open regedit.exe and navigate to HKEY_CLASSES_ROOT\*\shell
Add a new key and set its name to whatever you want the menu item to be called
Add a new key under that, with the name command
Double-click the (Default) value under the command key and set its value as follows:
if using the regular command prompt (note the double percentage signs):
cmd /c for /f "useback delims=" %%x in (`date /t`) do ren "%1" %%x
if using PowerShell:
cmd /c powershell Rename-Item "%1" (Get-Date -Format yyyy-MM-dd)
date /t