Renaming with last save date

Viewed 46

I have a problem with renaming files. My goal is renaming files with the last saving date. Unfortunately, by a wrong modification, the last modified dates are not the same as the last save date.

I tried to solve with this code in Powershell:

Get-ChildItem | Rename-Item -NewName {$_.basename + " " + $_.LastWriteTime.ToString("yyyy-MM-dd") + $_.Extension}

It would be great if the code put the last save date in the end of the filename. But I cant modify it to be correct.

I can sort the files in the File Explorer by last save date. I need these dates to be put in the of the filename.

Anyone could help me solve this?

1 Answers

Try using Get-Date to convert the file's LastWriteTime to a string.

Get-ChildItem | Rename-Item -NewName {$_.basename + " " + (Get-Date $_.LastWriteTime -Format "yyyy-MM-dd") + $_.Extension}
Related