Results 1 to 5 of 5

Thread: Directory listing

  1. #1

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303

    Question

    How can I get a list of say .PDF files in a given directory using ASP.

    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  2. #2
    Guest
    You could do it with the File System Object. This code would make a list of all the .pdf docs in the same directory as the ASP. Change 'strPath' to change the folder that's examined. If you didn't want to simply display the files you could put them into a dynamic array or something.

    Code:
    <%
    Dim objFSO
    Dim objFolder
    Dim objFile
    Dim strPath
    Dim strHTML
    
    strPath = Request.ServerVariables("APPL_PHYSICAL_PATH")
    
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(strpath)
    
    For Each objFile In objFolder.Files
      If InStr(1, objFile.Name, ".pdf") > 0 Then
        strHTML = strHTML & objFile.Name & "<BR>" & vbcrlf
      End If
    Next
      
    Response.Write strHTML
    
    Set objFile = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
    %>
    Paul

  3. #3

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    This worked great thanks.
    Do you know if its possible to display the Title of the PDF document instead of the file name?
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  4. #4
    Guest
    You're welcome. FSO is pretty slick but I don't think you could get at the title of the PDF without having some way to open up and examine the PDF itself (you'd need some kind of Adobe Acrobat object that may or may not exist). One thing you could do is (hope your PDFs are nicely named and) remove the .PDF extension to display the filename without extension like so:

    strHTML = strHTML & Mid$(objFile.Name, 1, Len(objFile.Name) - 4) & "<BR>" & vbcrlf

    rather than the...

    strHTML = strHTML & objFile.Name & "<BR>" & vbcrlf

    ...used in my previous example...which may or may not work for you.

    Cheers,
    Paul

  5. #5

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    Thanks. I'll have to see if its possible to have the names changed, thats not my department.

    I know I can get Cold Fusion to display the title, but I don't want to use it (I don't like it)
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

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