Answer the question
In order to leave comments, you need to log in
How to copy the name of the most recent file through the batch file?
Good afternoon! The task is to select the name of the most recent file in the directory and subdirectories, then put it in the logs. Did some digging and did something like this:
@echo **************************************************************>>C:\Windows\backup\last_file.log
@echo &date /t>>C:\Windows\backup\last_file.log
@echo &time /t>>C:\Windows\backup\last_file.log
for /f "delims=" %%i in ('dir C:\TEST\user\*.mac /B /A-D /OD /TA') do (set file=%%i )
echo %file% >> C:\Windows\backup\last_file.log
Answer the question
In order to leave comments, you need to log in
1. you forgot /S in the dir command
2. the main problem seems to be that dir only sorts within one subdirectory, so it will print the most recent in the last subdirectory, not the most recent across all subdirectories; this fact will complicate the implementation tenfold: dir should display the names along with the date-time, and then the whole sorting will have to be hand-coded, dividing the date into fields.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question