Use this as the Rename-Item part of the PowerShell -Command string:
Rename-Item -LiteralPath $_.FullName -NewName ( '{0} {1}{2}' -f $_.BaseName, (Get-Date -format 'yyyy-MM-dd'), $_.Extension )
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have the following command that was added to registry to automatically rename a file (right-click) with it's last write date as a timestamp at the end of the file name.
@="PowerShell.exe -WindowStyle Hidden -Command "( Get-Item -LiteralPath '%1' ) | %%{ Rename-Item -LiteralPath $.FullName -NewName ( '{0} {1:yyyy-MM-dd}{2}' -f $.BaseName, $.LastWriteTime, $.Extension ) }""
It does work really well. My problem is I want to change the LastWriteTime for a current date timestamp like Get-Date
. Which would also provide HH-mm-ss (yyyy-MM-dd HH-mm-ss). I have tried different formula without any success. Even without the time part. I am a complete noob with Powershell. I use some commands on a regular basis but I never have to code or change anything.
Would someone knows what needs to be changed in order to get filename.ext -> filenameCurrentdatetime.ext ?
Thanks!
Here is the complete registry key that was added to achieve the right-click auto-renaming on the file.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\RenameWithTimestamp]
@="Rename: Add Date Modified"
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\RenameWithTimestamp\Command]
@="PowerShell.exe -WindowStyle Hidden -Command "( Get-Item -LiteralPath '%1' ) | %%{ Rename-Item -LiteralPath $.FullName -NewName ( '{0} {1:yyyy-MM-dd}{2}' -f $.BaseName, $.LastWriteTime, $.Extension ) }""
Use this as the Rename-Item part of the PowerShell -Command string:
Rename-Item -LiteralPath $_.FullName -NewName ( '{0} {1}{2}' -f $_.BaseName, (Get-Date -format 'yyyy-MM-dd'), $_.Extension )