I wanted the 'touch' feature of cloning / duplicating the file dates from another file, natively, and be usable from a batch file.
So 'drag and drop' video file on to batch file, FFMPEG runs, then 'Date Created' and 'Date Modified' from the input file gets copied to the output file.
This seemed simple at first until you find batch files are terrible at handling unicode file names, in-line PowerShell messes up with file name symbols, and double escaping them is a nightmare.
My solution was make the 'touch' part a seperate PowerShell script which I called 'CLONE-FILE-DATE.ps1' and it contains:
(GI -LiteralPath $TargetPath).CreationTime = (GI -LiteralPath $SourcePath).CreationTime
(GI -LiteralPath $TargetPath).LastWriteTime = (GI -LiteralPath $SourcePath).LastWriteTime
Then here is example usage within my 'CONVERT.BAT' batch file:
%~dp0\ffmpeg -i "%~1" ACTION "%~1-output.mp4"
CHCP 65001 > nul && PowerShell -ExecutionPolicy ByPass -File "%~dp0\CLONE-FILE-DATE.PS1" "%~1" "%~1-output.mp4"
I think the PowerShell is readable, so will just explain the batch speak:
%~dp0 is the current directory of the batch file.
%~1 is the path of the file dropped onto the batch without quotes.
CHCP 65001 > nul sets characters to UTF-8 and swallows the output.
-ExecutionPolicy ByPass allows you to run PowerShell without needing to modify the global policy, which is there to prevent people accidentally running scripts.