Voodooman wrote:Btw, what is %%! ? why it act so different and makes sing word as variable instead of whole line?
That has nothing to do with %%! ?, but rather with the default delimeters, {TAB}, {space}, {COMMA}
Voodooman wrote:Can you explain a little %%! and %%? or %%$ which you use quite offten?
I try,
Generally it is considered good programming style not to use variables when you don't have to.
These 'short lifespan' values can be represented with tokens like %a, %b, %? or even %!.
In the example above I used %! which I now consider bad style cause the exclamation mark is special and normally needs to be escaped in delayed expansion. This is problematic when writing
macros.
So that leaves me with %a, %b or %?.
I suck at maths, but I do know my alphabet so I promote using tokens %a to %Z only when your for loop collects multiple 'tokens=1,2*'. In all other case, I use non-alphabetical tokens like %? to stand out.
Voodooman wrote:modified it a little to remove "file not found" from llist if no file with extenstion exist
I modify it again, you know it's faster to open a file for writing only once
Code: Select all
setlocal enableDelayedExpansion
set "$field=mpa,asf,avi,flv,mov,mp4,mpg,swf,vob,wmv"
> "list.txt" (
for %%? in (
!$field!
) do for /f "delims=" %%? in (
'2^>nul dir /b /o:gn "*.%%~?"'
) do (echo.%%?)
)
type "list.txt"
pause
exit /b
Note that I did not use file redirection in my original post to prove it wasn't necessary to solve the OP's problem.
See ya,