LoginSignup
1
0

フォルダー内のファイルの更新日をサブフォルダ含めて一括で変更する方法

Posted at

フォルダー内のファイルの更新日を変更する

何かの制約でフォルダー内のファイル更新日を変更したいとします。手で開いて保存を繰り返すのはどうかと思います。
そこで自動化しますが、開いて閉じてを繰り返すのではなく、windowsの機能を使い、ファイルを開かずに更新できます。

以下がそのスクリプトです。

$folderPath = 'C:\path\to\your\folder' # 変更したいフォルダのパス
Get-ChildItem -Path $folderPath -Recurse | ForEach-Object {
    if ($_.IsReadOnly) {
        $_.IsReadOnly = $false
    }
    $_.LastWriteTime = Get-Date
}

読み取り専用の場合はエラーになるので、それを解除しながら更新していきます。

以上です。

1
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
1
0