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?

More than 3 years have passed since last update.

PowerShell フォルダとその中のファイルの日付を一括で変更する方法

Posted at

タイトルの通り

[string] $time = "YYYY/MM/DD HH:MM"
[string] $rootDir = "<フォルダパス>"

Function main() {
    Set-ItemProperty $rootDir -Name CreationTime -Value "$time"
    Set-ItemProperty $rootDir -Name LastWriteTime -Value "$time"
    ChangeTimeStamp($rootDir)
}

Function ChangeTimeStamp($targetFolder) {

    cd $targetFolder
    $files = Get-ChildItem *

    # 取得した情報を一つ一つ処理する
    foreach($item in $files) {
        Write-Host $item.FullName
        Set-ItemProperty $item.FullName -Name CreationTime -Value "$time"
        Set-ItemProperty $item.FullName -Name LastWriteTime -Value "$time" 
        if($item.PSIsContainer)
        {
            ChangeTimeStamp($item.FullName)
        }
    }
}

main
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?