mardi 15 octobre 2019

Batch IF command not running

I'm trying to grab a couple of lines in some files and store them in variables (line3 and line4). Here is the code -

setlocal EnableDelayedExpansion

for /f "tokens=*" %%a in ('dir *.md /b /o:-n /a:-d') do (
call :getLines "%%a"
)

pause
exit

:getLines
set /A cnt=2
for /f "skip=4 tokens=*" %%b in (%1) do (
set /A cnt+=1
set "line!cnt!=%%b"
if !cnt! == 4 (
    set "filename=%~n1"
    set "blogdate=!filename:~0,10!"
    set "blogtitle=!filename:~11!"
    echo hello
    echo !line3!
    echo !line4!
    echo !filename!
    echo !blogdate!
    echo !blogtitle!
)
)
goto :eof

The above will not even echo "hello". I can't see what's wrong.

Aucun commentaire:

Enregistrer un commentaire