忍者ブログ

◆当blogは、Linuxサーバ構築する際の実際の設定手順を個人的メモとして記載しております。LinuC試験の役に立つ情報があるかも…?

LinuC(Linux技術者認定資格)&リナックスサーバ構築設定事例

   

【Linux】日付指定の圧縮

【以下の条件で圧縮】
 ・yyyymmdd と yyyy-mm-dd の両方の形式
 ・日付の範囲(8/3~8/31の例)
 
   tar -czvf logs-aug.tar.gz *_202608{03..31}_* *_2026-08-{03..31}_* 2> /dev/null
   zip -r logs-aug.tar.gz.zip *_202608{03..31}_* *_2026-08-{03..31}_* 2> /dev/null
 
【圧縮した内容の確認】
   tar -tzf logs-aug.tar.gz | head -n 20
   unzip -l logs-aug.zip | head -n 20
PR

【VBA】列結合

Sub CombineCSVColumnsFromList()
  '#********************** 
  '#【変数定義】
  '#********************** 
  Dim fso As Object
  Dim scriptPath As String, listPath As String
  Dim ts As Object, line As String
  Dim csvFiles() As String, fileCount As Long
  Dim i As Long, r As Long
  Dim currentBook As Workbook, targetSheet As Worksheet
  Dim csvBook As Workbook, csvSheet As Worksheet
  Dim lastRow As Long, maxRow As Long
  Dim firstFileName As String, nextFileName As String
  Dim currentDate As String, excelFileName As String
  
  '#********************** 
  '#① マクロを実行しているExcelファイルと
  '#同じフォルダーのパスを取得
  '#********************** 
  Set fso = CreateObject("Scripting.FileSystemObject")
  scriptPath = ThisWorkbook.Path
  listPath = fso.BuildPath(scriptPath, "list.txt") '● リストファイルのパス取得
  
  '#********************** 
  '#【リストファイルの存在チェック】
  '#********************** 
  If Not fso.FileExists(listPath) Then
      MsgBox "エラー: リストファイル無し", vbCritical
      Exit Sub
  End If
  
  '#********************** 
  '#② リストファイルから対象CSVのフルパス読込
  '#********************** 
  fileCount = 0
  Set ts = fso.OpenTextFile(listPath, 1) '● 1 = ForReading
  Do Until ts.AtEndOfStream
      line = Trim(ts.ReadLine)
      If line <> "" Then
          Dim fullPath As String
          fullPath = fso.BuildPath(scriptPath, line)
          If fso.FileExists(fullPath) Then
              ReDim Preserve csvFiles(fileCount)
              csvFiles(fileCount) = fullPath
              fileCount = fileCount + 1
          End If
      End If
  Loop
  ts.Close
  
  '#********************** 
  '#【ファイル数のチェック】
  '#********************** 
  If fileCount < 2 Then
      MsgBox "エラー: 対象CSVファイルが2個未満", vbCritical
      Exit Sub
  End If
  
  '#********************** 
  '#【エラーハンドリング開始】
  '#********************** 
  On Error GoTo ErrorHandler
  
  '#********************** 
  '#【処理速度の高速化】
  '#【画面更新、警告、自動計算をオフ】
  '#********************** 
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Application.Calculation = xlCalculationManual
  
  '#********************** 
  '#③ 新しいワークブックを作成
  '#書き込み対象のシートを設定
  '#********************** 
  Set currentBook = Workbooks.Add(xlWBATWorksheet)
  Set targetSheet = currentBook.Sheets(1)
  
  '#********************** 
  '#④ 1番目のCSVファイルを処理
  '#(1列目[A列] と *列目[*列] を抽出)
  '#********************** 
  firstFileName = fso.GetBaseName(csvFiles(0))
  Set csvBook = Workbooks.Open(csvFiles(0))
  Set csvSheet = csvBook.Sheets(1)
  
  lastRow = csvSheet.Cells(csvSheet.Rows.Count, "A").End(xlUp).Row
  maxRow = lastRow '● 基準となる行数を保持
  
  '#********************** 
  '#【ヘッダーの書き込み】
  '#********************** 
  targetSheet.Cells(1, 1).Value = "Col1"
  targetSheet.Cells(1, 2).Value = firstFileName
  
  '#********************** 
  '#【データのコピー】
  '#1個目のCSVファイルの1列、N列
  '#********************** 
  For r = 1 To maxRow
     targetSheet.Cells(r + 1, 1).Value = csvSheet.Cells(r, 1).Value '● 1列/A列 (H0)
  '#targetSheet.Cells(r + 1, 2).Value = csvSheet.Cells(r, 2).Value '● 2列/B列 (H1)
     targetSheet.Cells(r + 1, 2).Value = csvSheet.Cells(r, 3).Value '● 3列/C列 (H2)
  '#targetSheet.Cells(r + 1, 2).Value = csvSheet.Cells(r, 4).Value '● 4列/D列 (H3)
  '#targetSheet.Cells(r + 1, 2).Value = csvSheet.Cells(r, 5).Value '● 5列/E列 (H4)
  Next r
  csvBook.Close SaveChanges:=False
  
  '#********************** 
  '#⑤ 2個目以降のCSVファイルを処理
  '#(*列目[*列] のみを横に結合)
  '#********************** 
  For i = 1 To fileCount - 1
      nextFileName = fso.GetBaseName(csvFiles(i))
      Set csvBook = Workbooks.Open(csvFiles(i))
      Set csvSheet = csvBook.Sheets(1)
      
  '#********************** 
  '#【ヘッダーの書き込み】
  '#(C列、D列…と右へ追加)
  '#********************** 
      targetSheet.Cells(1, i + 2).Value = nextFileName
      
  '#********************** 
  '#【データのコピー】
  '#2個目のCSVファイルのN列
  '#********************** 
      For r = 1 To maxRow
      '#targetSheet.Cells(r + 1, i + 2).Value = csvSheet.Cells(r, 2).Value '● 2列/B列 (H1)
         targetSheet.Cells(r + 1, i + 2).Value = csvSheet.Cells(r, 3).Value '● 3列/C列 (H2)
      '#targetSheet.Cells(r + 1, i + 2).Value = csvSheet.Cells(r, 4).Value '● 4列/D列 (H3)
      '#targetSheet.Cells(r + 1, i + 2).Value = csvSheet.Cells(r, 5).Value '● 5列/E列 (H4)
      Next r
      csvBook.Close SaveChanges:=False
  Next i
  
  '#********************** 
  '#⑥ 列幅の自動調整 (AutoFit)
  '#********************** 
  targetSheet.UsedRange.Columns.AutoFit
  
  '#********************** 
  '#⑦ ファイル名を指定して保存
  '#Excel 97-2003形式(.xls)
  '#********************** 
  currentDate = Format(Date, "yyyyMMdd")
  excelFileName = "_" & firstFileName & "_" & currentDate & "_★" & ".xls"
  
  '#********************** 
  '#【xlExcel8 = 56】
  '#(Excel 97-2003 ブック形式)
  '#********************** 
  currentBook.SaveAs Filename:=fso.BuildPath(scriptPath, excelFileName), FileFormat:=56
  currentBook.Close SaveChanges:=False
  
  MsgBox "【処理完了】" & vbCrLf & excelFileName, vbInformation
  
'#********************** 
'#【終了処理】
'#(ExitProcedure)
'#********************** 
ExitProcedure:
  '#********************** 
  '#画面更新、警告、自動計算を元に戻す
  '#********************** 
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
  Application.Calculation = xlCalculationAutomatic
  Exit Sub
  
'#********************** 
'#【エラーハンドリング処理を実行】
'#(ErrorHandler)
'#********************** 
ErrorHandler:
  MsgBox "【予期せぬエラー発生の為、処理中断】" & vbCrLf & _
         "エラー番号: " & Err.Number & vbCrLf & _
         "エラー内容: " & Err.Description, vbCritical
  
  '#********************** 
  '#【開きっぱなしのCSVや作成中ファイルを閉じる】
  '#(必要に応じて実行)
  '#********************** 
  On Error Resume Next
  If Not csvBook Is Empty Then csvBook.Close SaveChanges:=False
  If Not currentBook Is Empty Then currentBook.Close SaveChanges:=False
  
  '#********************** 
  '#【終了処理(ExitProcedure)へ移動】
  '#********************** 
  Resume ExitProcedure
  
End Sub

【PowerShell】列結合

****************************************************
  powershell -ExecutionPolicy Bypass -File "列結合.ps1"
  (list.txtに記載したファイル名を対象に列結合する)
****************************************************
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$listPath = Join-Path $scriptPath "list.txt"
if (-not (Test-Path $listPath)) {
    Write-Error "Error: list.txt not found."
    exit
}
$csvLines = Get-Content -LiteralPath $listPath
$csvFiles = @()
foreach ($line in $csvLines) {
    if (-not [string]::IsNullOrWhiteSpace($line)) {
        $cleanLine = $line.Trim()
        $fullPath = Join-Path $scriptPath $cleanLine
        if (Test-Path $fullPath) {
            $csvFiles += Get-Item -LiteralPath $fullPath
        }
    }
}
if ($csvFiles.Count -lt 2) {
    Write-Error "Error: Needs 2 or more valid CSV files from list.txt."
    exit
}
$headers = 0..99 | ForEach-Object { "H$_" }
$firstCsv = Import-Csv -LiteralPath $csvFiles[0].FullName -Header $headers
$baseCsv = @()
$firstFileName = [string]$csvFiles[0].BaseName
foreach ($row in $firstCsv) {
    $properties = [ordered]@{
        "Col1"          = $row.H0
        $firstFileName = $row.H2
    }
    $baseCsv += New-Object PSObject -Property $properties
}
for ($fileIdx = 1; $fileIdx -lt $csvFiles.Count; $fileIdx++) {
    $nextCsv = Import-Csv -LiteralPath $csvFiles[$fileIdx].FullName -Header $headers
    $nextFileName = [string]$csvFiles[$fileIdx].BaseName
    
    for ($rowIdx = 0; $rowIdx -lt $baseCsv.Count; $rowIdx++) {
        $nextValue = $nextCsv[$rowIdx].H2
        $baseCsv[$rowIdx] | Add-Member -MemberType NoteProperty -Name $nextFileName -Value $nextValue -Force
    }
}
$tempCsv = "$scriptPath\temp_combined.csv"
$baseCsv | Export-Csv -LiteralPath $tempCsv -NoTypeInformation -Encoding utf8
$currentDate = Get-Date -Format "yyyyMMdd"
$excelFileName = "OUTPUT_${firstFileName}_${currentDate}.xls"
$excelPath = Join-Path $scriptPath $excelFileName
try {
    $excel = New-Object -ComObject Excel.Application
    $excel.Visible = $false
    $excel.DisplayAlerts = $false
    $workbook = $excel.Workbooks.Open($tempCsv)
    $worksheet = $workbook.Sheets.Item(1)
    $worksheet.UsedRange.Columns.AutoFit() | Out-Null
    $workbook.SaveAs($excelPath, 56)
    $workbook.Close()
}
finally {
    if ($excel) {
        $excel.Quit()
        [System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel) | Out-Null
        Remove-Variable excel -ErrorAction SilentlyContinue
    }
    if (Test-Path $tempCsv) { Remove-Item $tempCsv }
}

【BAT】WinSCP実行

@echo off
REM #*************************
REM # 変数定義
REM #*************************
set "TERATERM_DIR=C:\teraterm-5.4.1"
set "WINSCP_DIR=C:\WinSCP-6.5.6-Portable"
 
color 8a
echo *************************
echo TERATERM_DIR
echo *************************
echo WINSCP_DIR
echo *************************
timeout 2
 
REM #*************************
REM # メニュー画面の選択処理
REM #*************************
:MENU
cls
color 02
echo ====================================
echo   メニュー:実行する処理を選んでください
echo ====================================
echo  [1] Tera Term接続
echo  [2] WinSCP接続
echo  [q] 終了
echo ====================================
echo.
 
set /p CHOICE="メニューから選択 : "
if "%CHOICE%"=="1" goto RUN_01
if "%CHOICE%"=="2" goto RUN_02
if "%CHOICE%"=="q" goto TARGET_EXIT
 
REM #*************************
REM # 入力エラー処理
REM #*************************
color 04
echo 不正な入力です。1から3の数字を入力してください。
pause
goto MENU
 
REM #*************************
REM # 処理(1)
REM #*************************
:RUN_01
color 09
echo Tera Term マクロを起動
"%TERATERM_DIR%\ttpmacro.exe" "%USERPROFILE%\Desktop\LOGIN.ttl"
goto TARGET_END
 
REM #*************************
REM # 処理(2)
REM #*************************
:RUN_02
color 09
echo WinSCP を起動
"%WINSCP_DIR%\WinSCP.exe" sftp://<ユーザ>:<パスワード>@192.168.0.xx/ /rawsettings SshHostKeyPolicy=ad-hoc
goto TARGET_END
 
REM #*************************
REM # メニュー画面へ遷移
REM #*************************
:TARGET_END
color 08
echo.
echo メニューに戻ります。
timeout 2
goto MENU
 
REM #*************************
REM # 終了処理
REM #*************************
:TARGET_EXIT
color 07
echo 終了
timeout 2

【Linux】Bracketed Paste Mode

Bracketed Paste Mode
 ⇒ コマンドのペースト投入で回避する方法
 
① 一時的に無効化する場合
(現在のターミナル画面を閉じると設定はリセットされる)
 bind 'set enable-bracketed-paste off'
 
② 恒久的に無効化する場合
 ⇒ TERATERM.INIに以下を設定する
         BracketedSupport=off

【Linux】Ubuntu設定

#*****************************
# ■ アップデート
#*****************************
sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt autoremove
sudo reboot
 
#*****************************
# ■ SSH設定
#*****************************
sudo apt install ssh
sudo systemctl start ssh
sudo systemctl status ssh

【TTL】ListBoxログイン②

  ※※※※※※※※※※※※※※
  ※※※ TTL_ログイン.ttl ※※
  ※※※※※※※※※※※※※※
;*****************************
;■ 対象サーバ情報
;*****************************
strdim Server_NAME 4
Server_NAME[0] = '【サーバ名】'
Server_NAME[1] = '【サーバ名】'
Server_NAME[2] = '【サーバ名】'
Server_NAME[3] = '【サーバ名】'
;-----------------------------
strdim Server_IPaddress 4
Server_IPaddress[0] = '192.168.0.xx'
Server_IPaddress[1] = '192.168.0.xx'
Server_IPaddress[2] = '192.168.0.xx'
Server_IPaddress[3] = '192.168.0.xx'
;-----------------------------
strdim Server_USER 4
Server_USER[0] = '【ユーザID】'
Server_USER[1] = '【ユーザID】'
Server_USER[2] = '【ユーザID】'
Server_USER[3] = '【ユーザID】'
;-----------------------------
strdim Server_PASS 4
Server_PASS[0] = '【パスワード】'
Server_PASS[1] = '【パスワード】'
Server_PASS[2] = '【パスワード】'
Server_PASS[3] = '【パスワード】'
 
;*****************************
;■ サーバ選択画面
;*****************************
getdir TTL_Path
strconcat TTL_Path '\TTL_SSH.ttl'
include TTL_Path
 
;*****************************
;■ ログイン後にコマンド実行
;*****************************
pause 1
sendln
sendln
wait '$' '#'
sendln
send 'date ; uname -n ; id'
sendln
sendln
 
  ※※※※※※※※※※※※※※
  ※※※※TTL_SSH.ttl ※※※※
  ※※※※※※※※※※※※※※
 
;*****************************
;■ 選択画面の表示
;-----------------------------
listbox '『対象を選択してください』' '【サーバ名】' Server_NAME
;-----------------------------
;■ 選択したresult値を取得
if result >= 0 then
  paramIP = Server_IPaddress[result] ;; ■ IPアドレス
  paramUSER = Server_USER[result]    ;; ■ ユーザ名
  paramPASS = Server_PASS[result]    ;; ■ パスワード
  LOG_File = Server_NAME[result]     ;; ■ ログファイル名
else
  end
endif
 
;*****************************
;■ SSHログイン情報
;-----------------------------
;■ SSHの認証方式の設定
;-----------------------------
paramAUTH = 'password'               ;; ■ 認証方式の値
;-----------------------------
;■ INIファイルのパス設定
;-----------------------------
getdir macroDIR                      ;; ■ 現在のパス取得
strconcat macroDIR '\TERATERM.INI'   ;; ■ INIファイル名
paramINI = macroDIR                  ;; ■ INIファイルの値
 
;*****************************
;■ SSH接続コマンド編集
;-----------------------------
LoginSSH = paramIP                      ;; ■ IPアドレス
strconcat LoginSSH ':22 /ssh /2 /auth=' ;; ■ 認証方式オプション
strconcat LoginSSH paramAUTH            ;; ■ 認証方式の値
strconcat LoginSSH ' /user='            ;; ■ ユーザ名オプション
strconcat LoginSSH paramUSER            ;; ■ ユーザ名の値
strconcat LoginSSH ' /passwd='          ;; ■ パスワードオプション
strconcat LoginSSH paramPASS            ;; ■ パスワードの値
strconcat LoginSSH ' /F='               ;; ■ INIファイルオプション
strconcat LoginSSH paramINI             ;; ■ INIファイルの値
 
;*****************************
;■ LOGファイルの設定
;-----------------------------
getdir LOG_Path
strconcat LOG_Path '\LOG\'
getdate LogDate '_%Y%m%d-%H%M%S.log'
strconcat LOG_File LogDate
strconcat LOG_Path LOG_File
 
;*****************************
;■ SSH接続ログイン
;-----------------------------
;; messagebox LOG_Path 'デバッグ用メッセージ'
connect LoginSSH
logopen LOG_Path 0 0
 
;*****************************
;■ タイトル設定
;-----------------------------
settitle LOG_Path

【TTL】ListBoxログイン①

;*****************************
;■ SSHログイン情報
;*****************************
paramUSER = '<ユーザ名>     ;; ■ ユーザ名の値
paramPASS = '<パスワード>   ;; ■ パスワードの値
;*****************************
;■ SSHの認証方式の設定
;*****************************
paramAUTH = 'password'        ;; ■ 認証方式の値
;*****************************
;■ INIファイルのパス設定
;*****************************
getdir macroDIR                      ;; ■ 現在のパス取得
strconcat macroDIR '\TERATERM.INI' ;; ■ INIファイル名
paramINI = macroDIR                  ;; ■ INIファイルの値
;*****************************
;■ 表示するサーバ名の設定
;*****************************
strdim Server_NAME 5
Server_NAME[0] = '【サーバ名】'
Server_NAME[1] = '【サーバ名】'
Server_NAME[2] = '【サーバ名】'
Server_NAME[3] = '【サーバ名】'
Server_NAME[4] = '【サーバ名】'
;*****************************
;■ 対象IPアドレスの設定
;*****************************
strdim Server_IPaddress 5
Server_IPaddress[0] = '192.168.0.xx'
Server_IPaddress[1] = '192.168.0.xx'
Server_IPaddress[2] = '192.168.0.xx'
Server_IPaddress[3] = '192.168.0.xx'
Server_IPaddress[4] = '192.168.0.xx'
;*****************************
;■ 選択画面の表示
;*****************************
listbox '『対象を選択してください』' '【サーバ名】' Server_NAME
;*****************************
;■ 選択したresult値を取得
;*****************************
if result >= 0 then
    paramIP = Server_IPaddress[result]
    LOG_File = Server_NAME[result]
else
    end
endif
;*****************************
;■ SSH接続コマンド編集
;*****************************
LoginSSH = paramIP                      ;; ■ IPアドレス
strconcat LoginSSH ':22 /ssh /2 /auth=' ;; ■ 認証方式オプション
strconcat LoginSSH paramAUTH            ;; ■ 認証方式の値
strconcat LoginSSH ' /user='            ;; ■ ユーザ名オプション
strconcat LoginSSH paramUSER            ;; ■ ユーザ名の値
strconcat LoginSSH ' /passwd='          ;; ■ パスワードオプション
strconcat LoginSSH paramPASS            ;; ■ パスワードの値
strconcat LoginSSH ' /F='               ;; ■ INIファイルオプション
strconcat LoginSSH paramINI             ;; ■ INIファイルの値
;*****************************
;■ SSH接続ログイン
;*****************************
connect LoginSSH
;*****************************
;■ LOGファイルの設定
;*****************************
getdir LOG_Path
strconcat LOG_Path '\LOG\'
getdate LogDate '_%Y%m%d-%H%M%S.log'
strconcat LOG_File LogDate
strconcat LOG_Path LOG_File
logopen LOG_Path 1 1
;; messagebox LOG_Path 'デバッグ用メッセージ'
;*****************************
;■ タイトル設定
;-----------------------------
settitle LOG_Path

;*****************************
;■ プロンプト待ち&コマンド
;*****************************
wait '$' '#'
sendln
sendln
send 'date ; uname -n ; id'
sendln
sendln
wait '$' '#'
sendln

【awk】列の合計

#*****************************
#【ls 結果サイズを合計する】
#*****************************
ls -l | awk '{sum += $5} END {print sum}'
 
#*****************************
#【画面表示&ファイルに保存】
#*****************************
ls -l | awk '{sum += $5} END {print sum}' | tee result.txt
 
#*****************************
#【MB単位&小数点以下2桁】
#*****************************
ls -l | awk '{sum += $5} END {printf "%.2f MB\n", sum/1024/1024}'

【PowerShell】関数オブジェクト

REM ▼▲▼▲▼▲▼▲▼▲▼▲▼
REM ▼スクリプトファイル名  
REM ▲『WinMerge_Excel.bat』
REM ▲▼▲▼▲▼▲▼▲▼▲▼▲
 
@echo off
REM **************************
REM # conhost切替
REM **************************
if not "%1"=="am_admin" (
    start conhost "%~f0" am_admin & exit /b
)
 
REM **************************
REM # 画面サイズ設定
REM # カラー設定
REM # 文字コード設定
REM **************************
mode con: cols=120 lines=16
color 0a
chcp 932
 
timeout 1
 
REM **************************
REM # PowerShell実行
REM **************************
powershell -ExecutionPolicy RemoteSigned -File "%CD%\WinMerge_Excel.ps1"
 
timeout 5
 
REM **************************
REM # バッチ終了処理
REM **************************
color 17
cls
 
echo .
echo " ================= "
echo " ====== END ====== "
echo " ================= "
echo .
 
timeout 3
 
# ▼▲▼▲▼▲▼▲▼▲▼▲▼
# ▼スクリプトファイル名  
# ▲『WinMerge_Excel.ps1』
# ▲▼▲▼▲▼▲▼▲▼▲▼▲
 
#******************************
# ■ .NET クラス読込
#-----------------------------
Add-Type -AssemblyName System.Windows.Forms
 
#******************************
# ■ 定数設定
#-----------------------------
#【年月日-時分秒】
$DayTime = Get-Date -Format "yyyyMMdd-HHmmss"
 
#-----------------------------
#【WinMerge格納パス】
# ※ 環境に合わせて以下のパスを設定
$winMerge = "C:\Program Files\WinMerge\WinMergeU.exe"
 
#-----------------------------
#【ポップアップメッセージ】
$P_MSG_1 = "★★★★★ 【WinMerge】比較元(左側)ファイルを選択 ★★★★★"
$P_MSG_2 = "★★★★★ 【WinMerge】比較先(右側)ファイルを選択 ★★★★★"
$P_MSG_3 = "★★★★★ 【WinMerge】出力先を確認ください ★★★★★"
 
#-----------------------------
#【出力メッセージ】
$W_MSG_0 = " ================= "
$W_MSG_1 = " ※※※ 【PowerShell実行 ⇒ WinMerge】 ※※※ "
$W_MSG_2 = " ※※※ 比較元と比較先のファイルを確認ください ※※※ "
$W_MSG_3 = " ====== END ====== "
 
#-----------------------------
#【msgbox オブジェクト生成】
$msgbox = New-Object -ComObject Wscript.Shell
 
#-----------------------------
#【fileDialog オブジェクト生成】
$FileDialog = New-Object System.Windows.Forms.OpenFileDialog
$fileDialog.Title = "【★★★★★ 対象ファイルを選択してください ★★★★★】"
$FileDialog.Filter = "すべてのファイル (*.*)|*.*"
$fileDialog.ValidateNames = $false
$fileDialog.CheckFileExists = $false
$fileDialog.CheckPathExists = $true
 
#******************************
# ■ 関数設定
#-----------------------------
#【ダイアログからパス取得】
function Select_File {
  if ($FileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
    $filePath = $FileDialog.FileName
    #-----------------------------
    #【アクセスチェック】
    if (Test-Path -LiteralPath $filePath) {
      return $filePath
    } else {
        Write-Error "【*** Path ERROR ***】 : $_"
        exit
    }
  } else {
    Write-Host "選択無し(キャンセル)" -ForegroundColor Yellow
    exit
  }
}
 
#******************************
# ■ 処理開始メッセージ表示
#-----------------------------
Write-Host " "
Write-Host "$W_MSG_1"
Write-Host " "
 
Start-Sleep 1
 
#******************************
# ■ 比較元(左側)を選択
#-----------------------------
$msgbox.popup("$P_MSG_1")
$PATH_L = Select_File
 
Write-Host "【WinMerge】比較元(左側): $PATH_L"
 
Start-Sleep 1
 
#******************************
# ■ 比較先(右側)を選択
#******************************
$msgbox.popup("$P_MSG_2")
$PATH_R = Select_File
 
Write-Host "【WinMerge】比較先(右側): $PATH_R"
 
#******************************
# ■ 確認メッセージ表示
#-----------------------------
Write-Host " "
Write-Host "$W_MSG_2"
Write-Host " "
pause
 
#******************************
# ■ 出力先パス設定
#-----------------------------
# ## $OUTPUT_Path = [Environment]::GetFolderPath("Desktop")
# ## $OUTPUT_Path = (Get-Location).Path
$OUTPUT_Path = $PSScriptRoot
#-----------------------------
$msgbox.popup("$P_MSG_3")
Write-Host "**************************************"
Write-Host "【WinMerge】フォルダ名  : $OUTPUT_Path"
 
#******************************
# ■ HTMLパス取得(生成)
#-----------------------------
$HTML_File = "$OUTPUT_Path\Diff_HTML_$DayTime.html"
Get-ChildItem | Select-Object Name, Length | ConvertTo-Html > $HTML_File
#-----------------------------
Write-Host "【WinMerge】HTML名  : $HTML_File"
 
#******************************
# ■ WinMerge 比較実行
#-----------------------------
& $winMerge /r /noninteractive /or "$HTML_File" "$PATH_L" "$PATH_R"
 
#******************************
# ■ WinMerge比較結果を保存する
#-----------------------------
#【EXCELファイル名の設定】
$EXCEL_File = "$OUTPUT_Path\Diff_Excel_$DayTime.xlsx"
Write-Host "【WinMerge】エクセル名  : $EXCEL_File"
Write-Host "**************************************"
Write-Host " "
pause
 
#-----------------------------
#【EXCEL オブジェクト生成】
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $false
 
#-----------------------------
#【EXCEL ファイル保存処理】
try {
  $workbook = $excel.Workbooks.Open($HTML_File)
  $fileFormat = 51
  $workbook.SaveAs($EXCEL_File,$fileFormat)
  Write-Host " "
  Write-Host "【*** Excel保存完了 ***】 $EXCEL_File" -ForegroundColor Green
  Write-Host " "
}
catch {
  Write-Host " "
  Write-Error "【*** EXCEL ERROR ***】 : $_"
  Write-Host " "
}
 
#******************************
# ■ オブジェクト解放処理
#-----------------------------
finally {
  #-----------------------------
  #【EXCEL オブジェクト解放】
  if ($workbook) { 
    $workbook.Close($false)
  }
  $excel.Quit()
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
  Remove-Variable excel
 
  #-----------------------------
  #【fileDialog オブジェクト解放】
  $fileDialog.Dispose()
 
  #-----------------------------
  #【msgbox オブジェクト解放】
  $msgbox = $null
  if ($null -ne $msgbox) {
    [System.Runtime.InteropServices.Marshal]::ReleaseComObject($msgbox) | Out-Null
    #-----------------------------
    #【ガベージコレクション強制】
    [System.GC]::Collect()
    [System.GC]::WaitForPendingFinalizers()
  }
}
 
#******************************
# ■ 処理終了メッセージ表示
#-----------------------------
Write-Host " "
Write-Host "$W_MSG_0"
Write-Host "$W_MSG_3"
Write-Host "$W_MSG_0"
Write-Host " "
 
Start-Sleep 2

更新日付

07 2026/08 09
S M T W T F S
1
2 3 4 5 6 7 8
9 10 12 13 14 15
16 17 18 19 20 22
23 24 25 26 27 28
30 31

RECOMMEND

プロフィール

HN:
Account
HP:
性別:
非公開
職業:
--- NODATA ---
趣味:
--- NODATA ---
自己紹介:
◆当blogは、Linuxサーバ構築する際の実際の設定手順を個人的メモとして記載しております。LinuC試験の役に立つ情報があるかも…?

リンク

次のページ>>
Copyright ©  -- LinuC(Linux技術者認定資格)&リナックスサーバ構築設定事例 --  All Rights Reserved
Design by CriCri / Photo by Melonenmann / powered by NINJA TOOLS / 忍者ブログ / [PR]