Professional Web Applications Themes

Sorting a Query from CF Directory - Macromedia ColdFusion

I am using CF directory to display the contents of a file folder. I only want to show files with .ppt and .doc extensions. How can I filter out other file types? Here is my code: <cfdirectory action="list" directory="D:\Public\Sites\WBG Dev\ITP100"name="George" sort="dateLastModified DESC"> <cfoutput query="George"> <a href="#name#" target="_blank">#name#</a><br><br> </cfoutput>...

  1. #1

    Default Sorting a Query from CF Directory

    I am using CF directory to display the contents of a file folder. I only want
    to show files with .ppt and .doc extensions. How can I filter out other file
    types?

    Here is my code:

    <cfdirectory action="list" directory="D:\Public\Sites\WBG
    Dev\ITP100"name="George" sort="dateLastModified DESC">

    <cfoutput query="George">
    <a href="#name#" target="_blank">#name#</a><br><br>
    </cfoutput>

    murpg Guest

  2. #2

    Default Re: Sorting a Query from CF Directory

    One possibility from the
    http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-a20.htm


    No screen name said on May 10, 2005 at 1:32 PM :

    For those looking to filter multiple file types, try this:
    <cfdirectory action="list" directory="#your_dir# filter=".jpg"
    name="JPGList">
    <cfdirectory action="list" directory="#your_dir# filter=".gif"
    name="GIFList">
    <cfquery dbtype="query" name="MyList">
    SELECT * FROM JPGList
    UNION
    SELECT * FROM GIFList
    ORDER BY NAME
    </cfquery>




    mxstu Guest

  3. #3

    Default Re: Sorting a Query from CF Directory

    You can apply a filter to a CFDIRECTORY command in this form:

    cfdirectory action="list" directory="D:\Public\Sites\WBG Dev\ITP100"
    filter="*.ppt"

    With that approach you'd have to run it twice to get each of your file types.
    The other approach is simply to check the filename as you output it and only
    show those that match. In this example, you match the right 4 characters with
    your file extensions, converting to uppercase to handle extensions that might
    be different cases.

    -Paul





    <cfoutput query="George">
    <cfif (UCase(Right(name, 4) IS ".PPT")) OR (UCase(Right(name, 4)) IS ".DOC")>
    <a href="#name#" target="_blank">#name#</a><br><br>
    </cfif>
    </cfoutput>

    dempster Guest

  4. #4

    Default Re: Sorting a Query from CF Directory

    Easiest way is in your CFQUERY tag:

    <cfquery dbtype="query" name="listimages">
    SELECT Type, Name
    FROM George
    WHERE Type = <cfqueryparam cfsqltype="cf_sql_varchar" value="File">
    AND
    (Name LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%.ppt">
    OR Name LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%.doc">
    ORDER BY Name ASC
    </cfquery>

    Just keep adding more :

    OR Name LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%.doc"

    to the query to get additional file types.

    Abinidi Guest

Similar Threads

  1. Query of Queries is sorting when I don't want it to
    By angelseyeinc in forum Coldfusion Database Access
    Replies: 5
    Last Post: July 13th, 08:48 PM
  2. Sorting directory listing problem in Coldfusion
    By cf_menace in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: April 14th, 08:22 PM
  3. Sorting directory listing problem in Coldfusio
    By Rubex_Cube in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: April 11th, 08:53 PM
  4. Sorting a query based on URL variable
    By eddymilner in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: March 9th, 06:57 PM
  5. Sorting With a UNION Query?
    By MDW in forum ASP Database
    Replies: 2
    Last Post: June 10th, 03:25 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139