This week I decided to try to figure out an answer to a little problem that was posed to myself by myself. The problem is this; I output these html files but be able to easily select them through a web browser, instead of just opening them up as is.
The haphazard solution I created solves this problem, and I figured it would be fun to write up here.
Since the plan is to deploy this functionality to other coworkers I had to first make the solution work and second make it easy to deploy. However, I don’t deal with Windows (which is the platform) much when it comes to scripting and services, so it was a little touchy, to say the least.
The design came out to be fairly simple, create an index.html file that would have buttons that would point at the html files that the person wanted to show off. However, I wouldn’t know what they would be called or how many they would have. So, to batch I went.
I figured out a simple for loop that would read the .html file names and output them to a new file (seen below). This I then modified to output html around the filenames, to create the buttons for each file that exists. And instead of having the batch file create the whole html document from scratch, outputting every line, I cut up a .html document and left it unfinished. This batch file now creates a copy of that base foundation, then appends the buttons to the bottom of the file and lastly closes off the document.
DEL index.html COPY c:\www\start.htm c:\www\index.html setlocal enabledelayedexpansion set "parentfolder=%CD%" for /r . %%g in (*.htm*) do ( set "var=%%~nxg" IF !var!==start.htm ( echo. >> index.html ) IF !var!==index.html ( echo. >>index.html ) else ( echo ^<a href="!var!"^>^<button style="width:800px;height:200px"^>^<p style="font-size:30px"^>!var!^</p^>^</button^>^</a^>^<br/^>^<br/^> >> index.html echo. >> index.html ) ) echo ^</body^> >> index.html echo ^</html>^ >> index.html
I was a bit proud of this, since it was the first time I played with batch. And my normal solution with a python script would require more setup on the others’ computers, which I wanted to avoid. Now they simply have to add the .html files to the folder that contains this .bat file and starting .html file, run it and have an index file that has buttons for all of the other files.
In the end, the user doesn’t even need to know HTML to be able to generate a simple file that has buttons that point to different files.