前置き
テストデータ準備のために、日付のフォルダを連番で作りたい。
また、フォルダの更新日時も日付に合わせたい。
コマンドプロンプトでは扱いづらいため、PowerShellを使用する。
スクリプト
100日前から今日までの日付のフォルダを作成するスクリプト。
for( $i = -100; $i -le 0; $i++ )
{
$Date = (Get-Date).AddDays($i).Date
$Name = (Get-Date $Date -Format "yyyyMMdd")
New-Item $Name -ItemType Directory -Force
Set-ItemProperty $Name -Name LastWriteTime -Value $Date
}
New-Item -ItemType で Directory を指定。
既に存在している場合はエラーが出るため、-Force をつける。
Set-ItemProperty で 更新日時を修正。更新日時は $Date にする。
ファイルを作りたい場合
New-Item -ItemType を Directory から File に置き換えれば良い。