#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Los Angeles, CA
    Posts
    34
    Rep Power
    11

    Smile loop through all files in a folder


    Hello,

    Is there a way in ColdFusion to loop through all the files in a folder and drop some links on a page according to what's there?

    I've got a bunch of Excel pages and would love to be able to create a page that automatically links to them.

    Thanks,



    Peter
  2. #2
  3. No Profile Picture
    Web Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    58
    Rep Power
    11
    You have to use <cfdirectory action="list"> tags. See documentation for the tag description or else you can look in developer exchange for some custom tags
  4. #3
  5. Wickedwd.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    wickedwd.com
    Posts
    201
    Rep Power
    0

    Lightbulb Solution wickedwd.com style


    I'm not sure what you want to do, plus it's late and i'm tired, plus i've got a Final tomorrow and i should be studying instead of helping you, but i'm sure there will be a time when you help me in return. If not well then all i can say is

    This should get u started

    Code:
    <CFQUERY NAME="Exceltables" DATASOURCE="YourDatabaseName">
    SELECT TableID, Column Name1, Column Name 2, etc.
    FROM Table Name
    ORDER BY Whatever you want
    </CFQUERY>
    
    <!--- Provided by Alas from Wickedwd.com --->
    <!--- You're a dork if u erase my name --->
    <HTML>
    <HEAD>
        <TITLE>Excel Tables and such</TITLE>
    </HEAD>
    
    <BODY>
    
    <TABLE>
    <TR>
    
    <!--- remeber the TableID column is your primary key in the DB --->
    <CFOUTPUT QUERY="Exceltables">
    <TR>
     <TD>
      <B><A HREF="Pagewheretablesareat.cfm?TableID=#URLEncodedFormat(Trim(TableID))#">#ColumnName1 or 2, whatever#</A></B>
     </TD>
    </CFOUTPUT>
    </TABLE>
    
    </BODY>
    </HTML>
    Ps hope this helps, im off to study.

    Check u later,
    Alas
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,243
    Rep Power
    967
    I think the question was directed more at reading files from a directory, not a database. If this is indeed the case, then using <cfdirectory> is the best route.
  8. #5
  9. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,026
    Rep Power
    4210
    yeah, it's pretty easy, here's my version
    Code:
    <CFDIRECTORY NAME="myfiles"
      DIRECTORY="#ExpandPath('.')#" 
      FILTER="*.*m*"
      SORT="DateLastModified DESC">
    
    <h3>My Files</h3>
    <p><CFOUTPUT QUERY="myfiles">
    #myfiles.DateLastModified# <a href="#myfiles.Name#">#myfiles.Name#</a><br />
    </CFOUTPUT></p>
    this cfm sits inside the folder (the DIRECTORY parameter indicates the current folder) and reports only what's inside it (the HREF is relative)

    the filter pulls out only .*m* file extensions, e.g. .cfm, .htm, .html
    r937.com | rudy.ca
    please visit Simply SQL and buy my book

IMN logo majestic logo threadwatch logo seochat tools logo