How do I convert a list of files into links?
ColdFusion makes it easy to dynamically list out the files in a folder. Converting this list of files into a list of hyperlinks is pretty simple. This will only work if the folder is under your web root (or available as a virtual folder on your web server). First decide on the folder you will list:
<cfdirectory directory="c:\web\pdfs" name="pdffiles">
Next you need to loop over the files and output them. The link will be based on the folder and how it relates to your web server's document root. In the example above the folder was c:\web\pdfs. The pdfs folder is directly under web root. The links then would simply link to the /pdfs folder with the name being dynamic:
<cfoutput query="pdffiles"> <a href="/pdfs/#name#">#name#</a><br> </cfoutput>
This question was written by Raymond Camden
It was last updated on January 21, 2007.