#author("2025-11-14T11:27:01+09:00","","")
#author("2025-11-14T11:28:05+09:00","","")
[[ソフトウェア開発>SoftwareEngineering]] / [[PowerShell>PowerShell]] / [[ChangeDateTime>./]]

*ChangeDateTime [#ba2a2e98]
#highlightjs([javascript])
#highlightjs([powershell])
 # ----------------------------------------------------------
 # インポート
 # ----------------------------------------------------------
 Add-Type -AssemblyName System.Drawing
 Add-Type -AssemblyName System.Windows.Forms
 
 
 # ----------------------------------------------------------
 # 関数定義
 # ----------------------------------------------------------
 function New-Button {
     param (
         $Caption
     )
 
     $button = New-Object System.Windows.Forms.Button
     $button.Width  = 80
     $button.Height = 30
     $button.Text = $Caption
 
     return $button
 }
 
 
 
 function New-Label {
     param (
         $Caption
     )
 
     $label = New-Object System.Windows.Forms.Label
     $label.AutoSize = $true
     $label.Text = $Caption
     
     return $label
 }
 
 
 
 function New-TextBox {
     $textbox = New-Object System.Windows.Forms.TextBox
     return $textbox
 }
 
 
 
 function New-DateTimePicker {
     $picker = New-Object System.Windows.Forms.DateTimePicker
     return $picker
 }
 
 
 
 function Set-FileLastWriteTimeRecursive {
     param (
         $Path
     )
 
     $lastWriteTime = $lastWriteTimePicker.Value
     Get-ChildItem -Path $Path -Recurse -File | ForEach-Object {
         $fullFileName = $_.FullName
 
         Set-ItemProperty "${fullFileName}" -Name CreationTime  -Value $lastWriteTime
         Set-ItemProperty "${fullFileName}" -Name LastWriteTime -Value $lastWriteTime
     }
 }
 
 
 
 function Write-FileList {
     param (
         $Path
     )
     $writingFullFileName = "${Path}\filelist.txt"
 
     Get-ChildItem -Path $Path -Recurse -File | ForEach-Object {
         $lastWriteTime = (Get-Date $_.LastWriteTime -Format "yyyy-MM-dd HH:mm:ss")
         $relativePath  = ($_.FullName).Replace($Path, ".")
 
         "${lastWriteTime} ${relativePath}" | Out-File $writingFullFileName -Append -Encoding utf8
     }
 }
 
 
 
 # ----------------------------------------------------------
 # メイン画面
 # ----------------------------------------------------------
 $form = New-Object System.Windows.Forms.Form
 $form.Text = "ファイル作成日更新・ファイル更新日変更"
 $form.Width  = 640
 $form.Height = 190
 $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
 $form.MaximizeBox = $false
 
 
 
 # ----------------------------------------------------------
 # 
 # ----------------------------------------------------------
 $top = 20
 $sourceFullFolderNameLabel = New-Label('変更対象')
 $form.Controls.Add($sourceFullFolderNameLabel)
 
 $sourceFullFolderNameLabel.Location = New-Object System.Drawing.Point(20, $top)
 
 $sourceFullFolderNameTextBox = New-TextBox
 $form.Controls.Add($sourceFullFolderNameTextBox)
 
 $sourceFullFolderNameTextBox.Location = New-Object System.Drawing.Point(100, $top)
 $sourceFullFolderNameTextBox.Width  = 500
 $sourceFullFolderNameTextBox.Height = 80
 $sourceFullFolderNameTextBox.Text = ''
 $sourceFullFolderNameTextBox.AllowDrop = $true
 
 $sourceFullFolderNameTextBox.Add_DragDrop({
     foreach ($filename in $_.Data.GetData([System.Windows.Forms.DataFormats]::FileDrop)) {
         if ([System.IO.Directory]::Exists($filename)) {
             $sourceFullFolderNameTextBox.Text = $filename
         }
     }
 })
 $sourceFullFolderNameTextBox.Add_DragOver({
     foreach ($filename in $_.Data.GetData([System.Windows.Forms.DataFormats]::FileDrop)) {
         if ([System.IO.Directory]::Exists($filename)) {
             $_.Effect = [System.Windows.Forms.DragDropEffects]::All
         }
     }
 })
 
 
 
 # ----------------------------------------------------------
 # 抽出
 # ----------------------------------------------------------
 $top = 60
 $lastWriteTimeLabel = New-Label('日付')
 $form.Controls.Add($lastWriteTimeLabel)
 
 $lastWriteTimeLabel.Location = New-Object System.Drawing.Point(20, $top)
 
 $lastWriteTimePicker = New-DateTimePicker
 $form.Controls.Add($lastWriteTimePicker)
 
 $lastWriteTimePicker.Location = New-Object System.Drawing.Point(100, $top)
 $lastWriteTimePicker.Value = Get-Date
 $lastWriteTimePicker.Format = 8
 $lastWriteTimePicker.CustomFormat = 'yyyy-MM-dd HH:mm:ss'
 
 
 # ----------------------------------------------------------
 # 実行ボタン
 # ----------------------------------------------------------
 $top = 100
 $executeButton = New-Button('実行')
 $form.Controls.Add($executeButton)
 
 $executeButton.Location = New-Object System.Drawing.Point(520, $top)
 
 $executeButton.Add_Click({
     $source = $sourceFullFolderNameTextBox.Text
     Set-FileLastWriteTimeRecursive $source
     Write-FileList $source
     explorer "${source}"
 })
 
 
 
 # ----------------------------------------------------------
 # 画面表示
 # ----------------------------------------------------------
 $form.ShowDialog()

トップ   差分 履歴 リロード   一覧 検索 最終更新   ヘルプ   最終更新のRSS