Creating an HTML File List with VB - Opening the Dir.txt File and Creating the HTML File
(Page 4 of 5 )
To create the catalog HTML file:
- Create the HTML headings
- The dir file will have to be opened for input
- Read in a line
- Output the line in HTML format
- Skip to the next record
- Do 3-4 until finished
- Create the end of the HTML file
- Close the files
From the above pseudo code, you can tell there will be a file input, a file output, and a loop.
The subroutine will look like this
Private Sub cmdCatalog_Click
()
On Error GoTo Err_cmdCatalog_Click
'run directory listing
'put the path in the shell command where you put the dir.bat file
Dim RetVal
RetVal = Shell(txtLocation & "dir.bat", 1) ' Run dir.bat
'open file for input and output
'change path for your system
Open txtLocation & "dir.txt" For Input As #1
Open txtLocation & "catalog.htm" For Output As #2
'create HTML headings
Print #2, "<HTML><HEAD><TITLE>MY Pictures</TITLE></HEAD><BODY>"
Print #2, "<center><h1>My Pictures</h1></center>"
Print #2, "<OL>"
'create loop, open file
Do Until EOF(1)
'get line from file
Input #1, txtFile
'output line to catalog
Print #2, "<LI>"
Print #2, "<a href='" & txtFile & "'>" & txtFile & "</a><br>"
Print #2, "</LI>"
Loop
'create HTML end
Print #2, "</OL>"
Print #2, "</BODY></HTML>"
'close files
Close #1
Close #2
Exit_cmdCatalog_Click:
Exit Sub
Err_cmdCatalog_Click:
MsgBox Err.Description
Resume Exit_cmdCatalog_Click
End Sub
Next: Compiling the File and Wrapping Up >>
More Visual Basic Articles
More By Tim Haight