Can someone help me get this line right?

powershell Set-ItemProperty -LiteralPath '[NewVideo]' -Name CreationTimeUtc -Value ('[CreationTimeOfOldVideo]' -as [Datetime])

I am trying to rotate video files 90 degrees, while preserving the creation date of the original file. I have found the way to do the rotation using ffmpeg, but am stuck trying to copy the creation date to the new file. A search made me conclude that it should be possible with powershell (of which I know hardly anything)

This is what I have so far:

FOR /r %%I in (*.avi, *.mp4) DO CALL :loopbody "%%~fI" "%%~dpnI_%%~xI" "%%~tI"
ffmpeg -i %1 -c:v libx264 -crf 18 -maxrate 4000k -bufsize 4000k -c:a libvo_aacenc -q:a 100 -map_metadata 0 -preset veryslow -tune film -movflags +faststart %2
powershell Set-ItemProperty -LiteralPath '%2' -Name CreationTimeUtc -Value ('%3' -as [Datetime])

Which was thankfully copied from another user at this forum. The problem lies in the last line. The %3 variable is the cmd date ($~tI) of the old file, which usually is the LastModifiedDate, not the CreationDate. I need powershell to set the creationdate of the new file the same as the creationdate of the old file. I have done some experimenting with [oldfile].CreationTimeUTC, to no avail.

Help is much appreciated.

  • Thx @Ƭᴇcʜιᴇ007, works like a dream – Joost Nov 10 '15 at 8:26

Example Powershell command to get creation date of file:

(Get-ChildItem c:\path\yourFile.txt).CreationTime

Example Powershell command to set creation date of file:

(Get-ChildItem c:\path\yourFile.txt).CreationTime = '01/01/1900 12:42AM'

So as a one-liner to be used in the existing script as-is (instead of that last line) try something like:

powershell (Get-ChildItem '%2').CreationTime = (Get-ChildItem '%1').CreationTime

This will set the creation time of the new file (%2) to the creation time of the old file (%1).

This assumes %2 contains the new file's path/name and %1 contains the old file's path/name. :)

  • 1
    You can also use LastWriteTime instead of CreationTime to get/set file modification date. – Alexander Revo Nov 7 '20 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.