rksoftware

Visual Studio とか C# とかが好きです

PowerShell でファイルの作成日時を変更する

PowerShell でこんな感じです。指定のディレクトリ配下の作成日時、更新日時、アクセス日時を変更します。

$datetime = '2024/01/26'
$directory = 'C:\何か\'
Get-ChildItem -Recurse $directory | ForEach-Object { Set-ItemProperty -Path $_.FullName -Name CreationTime -Value $datetime; Set-ItemProperty -Path $_.FullName -Name LastWriteTime -Value $datetime; Set-ItemProperty -Path $_.FullName -Name LastAccessTime -Value $datetime; }

■ touch コマンドでは?

ファイルの日付を変えるとなると思いつくのは touch コマンド。Windows にはありませんが、WSL があれば使えました。

wsl touch ファイル名

しかし、この方法では更新日時しか変わらず作成日時が変わりませんでした。残念。