Skip to content

Instantly share code, notes, and snippets.

@uemuraj
Last active September 16, 2021 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uemuraj/64ba9feb95a5dd3cfeed0087ab7b20b5 to your computer and use it in GitHub Desktop.
Save uemuraj/64ba9feb95a5dd3cfeed0087ab7b20b5 to your computer and use it in GitHub Desktop.
Powershell でファイルのタイムスタンプをあれこれする

Powershell でファイルのタイムスタンプをあれこれする

> Get-ChildItem '.\新規 Text Document.txt' | Select-Object -Property CreationTime

CreationTime
------------
2021/06/30 11:31:54
> Get-ChildItem '.\新規 Text Document.txt' | Select-Object -Property LastWriteTime

LastWriteTime
-------------
2021/07/14 11:15:14
> Set-ItemProperty '.\新規 Text Document.txt' -Name LastWriteTime -Value '2021/07/14 06:09:00'

更新時刻に現在日時を混ぜて使いたいなら、環境変数を使うのが楽。
コマンドラインやバッチファイルから、以下の様に実行すると、シングルコーテーションの中身も置換されてから実行されるのでシンプル。

@powershell -Command "Set-ItemProperty '.\新規 Text Document.txt' -Name LastWriteTime -Value '%DATE% 01:01:00'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment