Click to See Complete Forum and Search --> : Does Anyone Know How To...


softweng
August 4th, 2000, 11:43 AM
I need to make a VB app that will read all the file names in a directory and stuff them into an array.
Then once I have all the file names I need to make a web page (HTML) that displays links to all the files in the array.
This directory is all .JPEG files that changes everyday and I need to make an easy way to access them.
My company wants them to be displayed as links on a web page for ease of use.
I am sure it is possible but I don't know how to do it.
Thanks in advance for your help!

Johnny101
August 4th, 2000, 02:02 PM
here is a piece of some code i wrote for directory browsing (with links). i did it with VBscript on an ASP page, but you should be able to modify it to get it to work with VB:

<%@ Language=VBScript %>
<%
dim fso
dim folders
dim ofolder
dim subfolder
dim sreturn
dim ofile

Sub GetDirFileList()
dim s,i
set fso = Server.CreateObject("Scripting.FileSystemObject")

if request.querystring("folder") = "" then
s = server.mappath(Request.ServerVariables("SCRIPT_NAME"))

for i = len(s) to 1 step -1
If mid(s, i, 1) = "/" Or mid(s, i, 1) = "\" then Exit for
next

s = Left(s, i)

set ofolder = fso.GetFolder(s)
else
set ofolder = fso.GetFolder(request.querystring("folder"))
response.write ofolder.name & "<P>"

end if

for Each ofile In ofolder.Files

sreturn = "<a href='" & ofile.path & "'>" & ofile.name & "</a><BR>"
response.write sreturn
next

End Sub

%>

<html>
<body>
<A href=default.asp>Back to Main Admin page</a><P>
<% GetDirFileList %>

</body>
</html>



you could easily modify the above routine to take a directoryname as a parameter and then loop through all the files. no need to build an array, but if you are required to do so, it shouldn't be that hard either. as for building the HTML file - most of the code is already here -just port it into VB. you wouldn't have any of the response.write statments along with a few other changes.

this should get you going.

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

khaldac
August 4th, 2000, 03:30 PM
You don't need a VB app to do this. Put the following code in an .asp file and point your browser at it:

<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
<%
Dim objFSO, objFolder, objFile
Dim sMapPath, strFile

'Change this folder to the one that holds your files
sMapPath= "C:\jpgs"
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder(sMapPath)
for Each objFile In objFolder.Files
If ucase(Right(objFile.Name,4))=".JPG" then
strFile = "<a href='" & objFile.path & "'>" & objFile.Name & "</A><BR>"
Response.Write strFile
End If
next
%>
</BODY>
</HTML>

softweng
August 4th, 2000, 03:45 PM
Ok I have copied the code into a .asp file. How do I run it now? I have never done anything with asp before. Thanks!

khaldac
August 4th, 2000, 04:56 PM
Do you have an existing web site you are using? If so, place a link to the .asp file onto one of the pages. click on the link to see the files.

If not, you'll need to set up a new site. That's a little too involved for me to go into here.