Here's the code for a java CFX to do that exact thing.


It will be a whole lot faster than a cfc.

---- snip ----


import com.allaire.cfx.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;


public class recursiveDir implements CustomTag{

public void processRequest( Request request, Response response ) throws
Exception{


    if (!request.attributeExists("dir") ||
!request.attributeExists("queryname"))
{
    throw new Exception("Attributes 'dir' and 'queryname' are
required.");
}

String dir = request.getAttribute("dir");
String queryname = request.getAttribute("queryname");
String[] columns = { "Type" , "Name", "Size", "LastModified"} ;
Query query = response.addQuery( queryname, columns ) ;

recurseInDirFrom(dir,query);
}

public void recurseInDirFrom(String dirItem, Query query) {
  File file;
  String list[];
  String type;
  String size;


  file = new File(dirItem);
  size = "" + file.length();
  Date lm = new Date(file.lastModified());
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  String modified = sdf.format(lm);
   
  if (file.isDirectory()) {
   list = file.list();
   for (int i = 0; i < list.length; i++)
    recurseInDirFrom(dirItem + File.separatorChar + list[i], query);
    type = "Directory";
  } else {
   type = "File";
  }


  int iRow = query.addRow() ;
  query.setData( iRow, 1, type ) ;
  query.setData( iRow, 2, dirItem ) ;
  query.setData( iRow, 3, size ) ;
  query.setData( iRow, 4, modified ) ;
}


}


---- snip ----

-----Original Message-----
From: Andrew Scott [mailto:[EMAIL PROTECTED]
Sent: 09 December 2003 06:51
To: CF-Talk
Subject: RE: CFC and ColdfusionQueries


Here it is raymond,


If you comment the case statement Dir out, it works fine, but it
refuse to
work with it in there.

<cfcomponent displayname="DirectoryTools">

<cfset variables.filelist=QueryNew('FileName,FileDate,Size') />

<cffunction name="getDirectory" access="public" returntype="any"
output="true">
  <cfargument name="Directory" required="yes" />


  <cfdirectory action="" directory="#arguments.Directory#"
name="list">
  <cfloop query="list">
   <cfscript>
   switch (type)
   {
    case 'File':
     QueryAddRow(variables.filelist);

QuerySetCell(variables.filelist,'FileName',arguments.Directory & name);

QuerySetCell(variables.filelist,'FileDate',DateLastModified);
     QuerySetCell(variables.filelist,'Size',Size);
     break;
    case 'Dir':
     getDirectory(arguments.Directory & name );
     break;
   }
   </cfscript>
  </cfloop>
  <cfset variables.filelist='' />
</cffunction>


</cfcomponent>



Regards
Andrew Scott
Technical Consultant

NuSphere Pty Ltd
Level 2/33 Bank Street
South Melbourne, Victoria, 3205

Phone: 03 9686 0485  -  Fax: 03 9699 7976   

  _____  

From: Raymond Camden [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 9 December 2003 5:25 PM
To: CF-Talk
Subject: RE: CFC and ColdfusionQueries

Can you show us all of the code?
  _____
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to