0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

タイムスタンプを別のファイルからコピーする(バッチ+PowerShell)

Posted at

ファイルをAからA'に加工するバッチファイルがあるのですが、ファイルの更新日時もコピーしたくなりました。
更新日時の変更にはPowerShellが必要になるようでバッチからps1ファイルを呼び出す形で対応しました。

更新日時コピー処理(ps1)

まずは更新日時をコピーする汎用処理をps1スクリプトとして作っておきます

copy-timestamp.ps1
$date_update = (Get-ItemProperty $Args[0]).LastWriteTime
Set-ItemProperty $Args[1] -name LastWriteTime -value $date_update

第1引数のファイルの更新日時を取得し、第2引数のファイルに反映しています

バッチファイルから呼び出し

上記PowerShellスクリプトをバッチファイルから呼び出すには、以下の2行目のように呼び出します。

fix-video.bat
ffmpeg -i %1 -c:v copy -c:a copy "%~dpn1.fix%~x1"
powershell -ExecutionPolicy Unrestricted -File "%~dp0copy-timestamp.ps1" %1 "%~dpn1.fix%~x1"

batファイルとps1ファイルは同じフォルダにあることを前提としています。(%~dp0の部分の通り)

ちなみに、このバッチファイルの1行目はドラッグ&ドロップで動画ファイルを渡されるとffmpegで修復を試みるものです。
video.mp4というファイルを渡すと隣にvideo.fix.mp4というファイルを作るのですが、タイムスタンプが現在日時になって少し気になっていたところでした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?