PDA

Click to See Complete Forum and Search --> : Directory listing


parkes
Nov 13th, 2000, 05:57 AM
How can I get a list of say .PDF files in a given directory using ASP.

Nov 13th, 2000, 09:54 AM
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.


<%
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

parkes
Nov 13th, 2000, 10:18 AM
This worked great thanks.
Do you know if its possible to display the Title of the PDF document instead of the file name?

Nov 13th, 2000, 10:27 AM
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

parkes
Nov 13th, 2000, 10:34 AM
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)