Batch regex parse to html

April 1, 2009 at 18:26:16
Specs: Windows 7, NA
I'm trying to write a batch file that will list the files in the current directory (dir /b) search for a string/line containing the right filetype, and modify an html file to create links to each file.

IE: Current dir contains:
test1.avi
junk.zip
test2.avi
test3.avi
morejunk.doc

output:
[html]
[body]
[a href="test1.avi"]
[a href="test2.avi"]
[a href="test3.avi"]
[/body]
[/html]

Here is what I have, sadly it can only find an exact string:

@echo off
if exist temp.txt del temp.txt
if exist test.html del test.html
dir /b > test.txt

echo [html] > test.html
echo [head] >> test.html
echo [/head] >> test.html
echo [body] >> test.html


for /f "tokens=*" %%a in (test.txt) do call :FindAdd "%%a
echo [/body]>> test.html
echo [/html]>> test.html
exit /b


:FindAdd %1
set Text=%~1%
if "%Text%"=="test.avi" echo [a href="%Text%"] >> test.html
exit /b


See More: Batch regex parse to html

Report •


#1
April 1, 2009 at 22:47:56
modify this:
for /f "tokens=*" %%a in (test.txt) do call :FindAdd "%%a

:FindAdd %1
set Text=%~1%
if "%Text%"=="test.avi" echo [a href="%Text%"] >> test.html
exit /b


to:
for /f "tokens=*" %%a in ('type test.txt^|findstr/r "test[0-9].avi"') do (
echo [a href="%%a"]>>test.html
)


Report •
Related Solutions


Ask Question