Development Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsCommunityDevelopment Tutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 5th, 2004, 08:16 AM
FrankManno FrankManno is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 42 FrankManno User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.&nbsp; How do you do this
without having to manually code the HTML file? The following instructions will
show you how.&nbsp;


Read the full article here: Creating an HTML File List with VB

Reply With Quote
  #2  
Old January 5th, 2004, 10:01 AM
iwan iwan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 iwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old January 6th, 2004, 05:33 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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

Reply With Quote
  #4  
Old January 6th, 2004, 02:28 PM
twhaight twhaight is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Spokane, WA
Posts: 7 twhaight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old January 6th, 2004, 02:35 PM
twhaight twhaight is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Spokane, WA
Posts: 7 twhaight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old January 7th, 2004, 03:36 AM
iwan iwan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 iwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb

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.

Reply With Quote
  #7  
Old January 7th, 2004, 09:39 AM
twhaight twhaight is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Spokane, WA
Posts: 7 twhaight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
FS Methods

I will check it out. Thanks.

Reply With Quote
  #8  
Old January 11th, 2004, 10:20 AM
DavidM DavidM is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 78 DavidM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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.

Reply With Quote
  #9  
Old January 14th, 2004, 07:58 PM
twhaight twhaight is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Spokane, WA
Posts: 7 twhaight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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
Thanks for the suggestions.

Reply With Quote
  #10  
Old June 4th, 2004, 09:29 AM
Gene Gene is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 Gene User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsCommunityDevelopment Tutorials > Article Discussion: Creating an HTML File List with VB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT