CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Does Anyone Know How To...

    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!

    Kris
    Software Engineer
    Phoenix, AZ USA

  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Does Anyone Know How To...

    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
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Jul 2000
    Location
    Washington
    Posts
    77

    Re: Does Anyone Know How To...

    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>





  4. #4
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: Does Anyone Know How To...

    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!

    Kris
    Software Engineer
    Phoenix, AZ USA

  5. #5
    Join Date
    Jul 2000
    Location
    Washington
    Posts
    77

    Re: Does Anyone Know How To...

    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.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured