I
I
Ivan Malyshev2014-08-01 12:42:01
Automation
Ivan Malyshev, 2014-08-01 12:42:01

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

2 answer(s)
F
falsebyte, 2014-08-01
@yos

@echo off
for /f "delims=" %%i in ('dir C:\*.bat /B /A-D /OD /TA') do (set file=%%i )
echo %file%
pause

A
Andrew, 2014-08-01
@OLS

Add between /f and %%i an indication that you consider as separators some character that never occurs in your file names, for example "^":
and then the script will no longer consider spaces as column separators.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question