Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing first file in DIR command to a variable

Tags:

batch-file

I want to pass the very first file returned by

dir *.png /B

into the variable %firstFile%

like image 824
Mambo4 Avatar asked Dec 27 '22 04:12

Mambo4


2 Answers

Why do you need dir?

for %%x in (*.png) do if not defined firstFile set "firstFile=%%x"
like image 192
Joey Avatar answered Dec 29 '22 17:12

Joey


why do you need to iterate over all of the list?

for  %%x in (*.*) do (
  set "firstFile=%%x"
  goto :done
)
:done 
like image 24
PA. Avatar answered Dec 29 '22 17:12

PA.