I have a folder with media files named by timestamp like following yyyyMMdd_HHmmss_*.*. I need to rename them to yyyy-MM-dd HH-mm-ss *.*
For example I need to rename file 20181019_210353_BURST2.jpg to 2018-10-19 21-03-53 BURST2.jpg
There is a my ugly approach
PS E:> gci | Rename-Item -NewName { $_.Name.Substring(0,4) + '-' + $_.Name.Substring(4,2) + '-' + $_.Name.Substring(6,2) + ' ' + $_.Name.Substring(9,2) + '-' + $_.Name.Substring(11,2) + '-' + $_.Name.Substring(13,2) + $_.Name.Substring(15) }
What is the right command to obtain my purpose?
Your method will work, but you will need to provide a
-Pathparameter toRename-Item. The short answer is that the string will need to be broken down into the components to use in the new name.If you want to have some regex fun, you could use something like this. When you are convinced that the files will be renamed correctly, remove the
-WhatIffrom theRename-Itemcommand.