I want the first line of a DIR output in an environment variable. I tried
dir *.bat /T:C /O:-D /B | set /P test=
That didn't set the variable. I got it running using the following command:
FOR /F "tokens=*" %I IN ('dir *.bat /T:C /O:D /B') DO SET test=%I) >NUL
Since FOR will loop through the whole directory listing, I don't really like it and would prefer to use the piping instead. Going through an external file is not an option.