Gostaria de selecionar apenas o último item
(here: file432.txt) and perform further operations (e.g. copy and rename) on that file.
Use o seguinte arquivo em lotes.
test.cmd:
@echo off
setlocal
for /r . %%g in (file*.txt) do (
set _lastitem=%%g
)
echo do something to the last file in the list, which is %_lastitem%
endlocal
exemplo de saída:
F:\test>dir file*.txt
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test
22/08/2016 18:17 0 file101.txt
22/08/2016 18:17 0 file212.txt
22/08/2016 18:17 0 file432.txt
3 File(s) 0 bytes
0 Dir(s) 1,765,302,566,912 bytes free
F:\test>test
do something to the last file in the list, which is F:\test\file432.txt
F:\test>