Answer the question
In order to leave comments, you need to log in
How to find the newest file via bat?
Hello, you need to use bat to determine the newest file or the last modified one (in my case there will be no difference)
I googled such a command that shows the latest file, but did not figure out how it works.
for /f %%i in ('dir /b /T:A /A:-D /O:-D *.xls')
Answer the question
In order to leave comments, you need to log in
Your example is not a finished command. In the final form it will look something like this:
set "filename="
for /f %%i in ('dir /b /T:A /A:-D /O:-D *.xls') do (
set "filename=%%~i"
goto:finloop
)
:finloop
echo.%filename%
Good afternoon.
part of this topic. There is a folder, there are different Excel files in it, the task is to copy the most recent by date of update, copy it to another folder and add a name so that a story is created.
There is a working setup, but it takes the correct month, but does not take into account the date and time, i.e. if there are files from the 4th and 10, then it will copy the 4th.
Where is the mistake:
@ECHO off
setlocal
CHCP 65001
SET EXT=.xlsx
SET FOLDER=G:\localuser\Documents\13_Warehouse_report\Slots\test\
SET BACKUP_FOLDER=G:\localuser\Documents\13_Warehouse_report\Slots\
SET DATE=%date:~6,4%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%
for /F "delims=" %%A in ('DIR "%FOLDER%*%EXT%" /T:A /A:-D /B') DO SET NEW_FILE=%%~nA
copy "%FOLDER%%NEW_FILE%%EXT%" "%BACKUP_FOLDER%%NEW_FILE%_%DATE%%EXT%"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question