LoginSignup
0
0

拡張子を変更しファイルを移動させる

Posted at

PowerShell ISEを開き記述し、実行したいフォルダに保存する


# Excel アプリケーションオブジェクトを作成
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false

# カレントディレクトリ内のすべての .xls ファイルを取得
$xlsFiles = Get-ChildItem -Path .\*.xls

# 各 .xls ファイルに対して処理を実行
foreach ($file in $xlsFiles) {
    $filePath = $file.FullName
    $newFilePath = $filePath -replace "\.xls$", ".xlsx"

    # ワークブックを開く
    $workbook = $excel.Workbooks.Open($filePath)

    # .xlsx 形式で保存
    $workbook.SaveAs($newFilePath, 51) # 51 は .xlsx 形式を意味する
    $workbook.Close()
}

# Excel アプリケーションを閉じる
$excel.Quit()

# COM オブジェクトのリリース
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
Remove-Variable excel

メモ帳を開き.batで保存する


# Excelファイルの移動
@echo off

REM File move

REM xlsフォルダが存在しない場合にのみ作成
if not exist "xlsx\" mkdir xlsx

REM .xlsファイルをxlsフォルダに移動
move /-Y *.xlsx .\xlsx\

exit

作業手順


1.フォルダに.xlsファイルを格納する

2.PowerShellを開きPS1を実行する

3.batchファイルを実行する


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