|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Article Discussion: Creating an HTML File List with VB
You just got that shiny new digital camera and then you downloaded a bunch of
digital pictures to your computer. Next you want to create a simple Hypertext Markup Language (HTML) file so that you can burn the picture and HTML files to a CD that you can send to all your friends and family. How do you do this without having to manually code the HTML file? The following instructions will show you how. Read the full article here: Creating an HTML File List with VB |
|
#2
|
|||
|
|||
|
The techniques used in this article seem a bit out-of-fasion. Why use a batch file for getting the file list? You could code this directly in vb either using the dir command or the scripting.filesystemobject.
|
|
#3
|
||||
|
||||
|
Most decent image handling apps these days can make photo albums automatically too. E.g. Photoshop, Dreamweaver, Fireworks, Acdsee... not that you'd learn anything doing it this way
![]() |
|
#4
|
|||
|
|||
|
Batch File vs Shell Command
I used the batch file because some versions of Windows (those that run on a Win NT kernel), such as 2000, do not have dir.com. So if you were to use a shell command to run the 2 dir commands, you would get a "file not found error".
For versions of Windows that run on the Win 95 kernel (win 95, 98, etc) you could run 2 shell commands instead of the batch file. I'm sure there are a many ways to do this . If you have suggestions, feel free to send them. |
|
#5
|
|||
|
|||
|
Photoshop, etc
It is true, most of the photo editing software that comes with the digital camera will do things like slideshows, contact sheets, etc.
My objective in creating this applicaiton was to create a simple to use program for creating a HTML page of digital photos that is useful in creating a contact sheet or burning onto a CD. |
|
#6
|
|||
|
|||
|
i didn't mean you should shell dir.com, you should use vb's built-in fs methods such as dir...
![]() A simple example: Code:
'// Definitions
Dim arrFileTypes(3) As String
Dim strFolderPath As String
Dim strFile As String
Dim f As Long
'// Filetypes you want to list
arrFileTypes(0) = "*.jpg"
arrFileTypes(1) = "*.jpeg"
arrFileTypes(2) = "*.gif"
arrFileTypes(3) = "*.bmp"
'// Folder to scan
strFolderPath = "c:\images\"
'//set path
ChDrive Left(strFolderPath, 3)
ChDir strFolderPath
'// Itterate trough filetypes
For f = LBound(arrFileTypes) To UBound(arrFileTypes)
'// Get first file of current type
strFile = Dir(arrFileTypes(f))
'// Itterate trough files of current type
Do Until Len(strFile) = 0
'// outputs the current file
Debug.Print "["; strFile; "]"
'// get the next file
strFile = Dir()
Loop
Next f
This enables better program flow, error handling, etc. Plus you have no external batch files or other dependancies. The scripting.filesystemobject would be even faster, but it's a bit harder to use. You have to reference the 'Microsoft Scripting Runtime' library to enable this object. |
|
#7
|
|||
|
|||
|
FS Methods
I will check it out. Thanks.
|
|
#8
|
|||
|
|||
|
Why would anyone need to use a batch file to perform a directory listing.
Seems very kludgy and totally unprofessional. It would seem exactly like the type of programs our programmers try and throw across my desk all the time. Iwan's solution is the best approach or using the FileSystemObject. |
|
#9
|
|||
|
|||
|
Revision to VB Catalog
Thanks for the suggestions. I created a sub routines called GetFileList and call it from my click event.
I also changed the path from the hardcoded ones to the path put in a text box. Here are the revised sub routines: Code:
Sub GetFileList()
'// Definitions
Dim arrFileTypes(3) As String
Dim strFolderPath As String
Dim strFile As String
Dim f As Long
'// Filetypes you want to list
arrFileTypes(0) = "*.jpg"
arrFileTypes(1) = "*.jpeg"
arrFileTypes(2) = "*.gif"
arrFileTypes(3) = "*.bmp"
'// Folder to scan
strFolderPath = txtLocation
'//set path
ChDrive Left(strFolderPath, 3)
ChDir strFolderPath
'// Itterate trough filetypes
Open txtLocation + "\dir.txt" For Output As #2
For f = LBound(arrFileTypes) To UBound(arrFileTypes)
'// Get first file of current type
strFile = Dir(arrFileTypes(f))
'// Itterate trough files of current type
Do Until Len(strFile) = 0
'// outputs the current file
Debug.Print strFile
Print #2, strFile
'// get the next file
strFile = Dir()
Loop
Next f
Close #2
End Sub
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
Call GetFileList
'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>"
'create loop, open file
Do Until EOF(1)
'get line from file
Input #1, txtFile
'output line to catalog
Print #2, "<a href='" & txtFile & "'>" & "<img src='" & txtFile & "' height=100 width=100>" & "</a>"
Loop
'create HTML end
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
|
|
#10
|
|||
|
|||
|
Thanks for the code you supplied twhaight!
In my particular project I'm trying to get the list of files in a single directory and then create individual m3u files (plain text files with the path to the file). Most code out there right now just creates one m3u file with all the references to the mp3 files for streaming. That sucks in my opinion. Optimally, I would then like it to create a single HTML file with a drop-down menu listing all the file names and linking to the individual m3u files. The end result would funcion like the first drop-down menu on the left-hand side of www.holyhacker.com/ttb/. Unfortunately I had to do all those by hand and would much rather just run a script that creates all the stuff for me. That's the next step after I just get it to create individual m3u files. So far I've only modified a couple things in your code to help me out with this: 1. Dim arrFileTypes(0) As String 2. arrFileTypes(0) = "*.mp3" I deleted the search array for the other three file types, because I don't need them. For now I have it creating catalog.txt instead of catalog.htm and only displaying txtField: Print #2, strFile For now I'm not concerned about all the HTML, so I deleted the header and footer stuff also. I'll worry about adding in the path later because that's not difficult. Here's the bugger... The dir.txt file comes out great: 01031 Gen. 1_2.mp3 01032 Gen. 1_3-5.mp3 01033 Gen. 1_6-8.mp3 01034 Gen. 1_9-13.mp3 01035 Gen. 1_14-19.mp3 01036 Gen. 1_20-23.mp3 01037 Gen. 1_24, 25.mp3 01038 Gen. 1_26-31.mp3 But not the catalog.txt 1031 Gen. 1_2.mp3 1032 Gen. 1_3-5.mp3 1033 Gen. 1_6-8.mp3 1034 Gen. 1_9-13.mp3 1035 Gen. 1_14-19.mp3 1036 Gen. 1_20-23.mp3 1037 Gen. 1_24 25 1038 Gen. 1_26-31.mp3 Two perplexities here. 1) why does it mutilate the text going from dir.txt to catalog.txt? 2) where would I put the: Open txtLocation & "\" & txtfile & ".m3u" For Output As #2 to have it loop and create each individual file with the name from the list? Like so: 01031 Gen. 1_2.m3u 01032 Gen. 1_3-5.m3u 01033 Gen. 1_6-8.m3u 01034 Gen. 1_9-13.m3u 01035 Gen. 1_14-19.m3u 01036 Gen. 1_20-23.m3u 01037 Gen. 1_24, 25.m3u 01038 Gen. 1_26-31.m3u If this is way too confusing, I'm sorry. I don't really expect anyone to take any considerable time on this and would just like a quick answer if anyone knows one off-hand. It would be greatly appreciated. Thanks, Gene |
![]() |
| Viewing: Dev Articles Community Forums > Community > Development Tutorials > Article Discussion: Creating an HTML File List with VB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|