前提
指定フォルダは「C:\Users\user\Desktop\test」。
対象ファイルは「aioueo_*」の最新ファイルのみ。
![「aiueo_*」の最新ファイルは「aioueo_02.txt」。](https://it-skill-memo.work/wp-content/uploads/2021/09/bat_newest_file_001.png.png)
サンプルプログラム
@ECHO OFF
REM 対象フォルダ
SET targetFolder=C:\Users\user\Desktop\test\
REM 対象ファイル
SET targetFiles=aioueo_*
REM 対象フォルダ配下の対象ファイルを取得するコマンド(更新日付で降順)を作成
SET getFileListCmd=DIR /b /O-d %targetFolder%%targetFiles%
REM 更新日付が1番新しい1ファイルのみを処理する
FOR /F %%a IN ('%getFileListCmd%') DO (
ECHO タイムスタンプが1番新しいファイル:%%a
ECHO.
goto break
)
:break
PAUSE
EXIT
実行結果
指定フォルダ配下の指定ファイル(最新ファイルのみ)を処理できました。
![実行結果](https://it-skill-memo.work/wp-content/uploads/2021/09/bat_newest_file_002.png.png)