Answer the question
In order to leave comments, you need to log in
How can I select the most recent file by a specific extension in a BAT file?
There was a task: Check a certain directory for the appearance of new files in it, as soon as a new file appears, it must be sent by email.
I figured out how to send the file, I will send it using BLAT, but I don’t understand how to tell BLAT that I want to send the latest file.
I googled this command which shows the most recent file for /f %%i in ('dir /b /T:A /A:-D /O:-D *.xls')
but this command does not display the full filename if it contains a space.
Gentlemen, help me solve this problem. How to get the name of the most recent file?
Answer the question
In order to leave comments, you need to log in
@echo off
for /f "delims=" %%i in ('dir C:\*.bat /B /A-D /OD /TA') do (set file=%%i )
echo %file%
pause
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question