Hi,

In my application I'm using the following CFC. This gets loaded everytime a user click on a file link to get the file information (date, size, etc.).
I've been told that I could speed things up substantially by just having one function do a
single COM connection and have the other functions just re-use the COM
connection (COM connections have to go through a login process each time
that obviously have a lot of overhead).

How can I do this?

Do I put the code in my application.cfm and then just reuse it? If so, how?

Below is the code I got off cflib.org


--CFSCRIPT--
/**
* Returns the date/time a folder (directory) was created. (Windows only)
*
* @param path Absolute or relative path to the specified folder.
* @return Returns a date/time object.
* @author Rob Brooks-Bilson ([EMAIL PROTECTED])
* @version 1.0, July 20, 2001
*/
function FolderSize(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var folder = fso.Getfolder(path);
  Return folder.Size;
}
function FolderDateLastAccessed(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var folder = fso.GetFolder(path);
  Return folder.DateLastAccessed;
}
function FolderDateLastModified(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var folder = fso.GetFolder(path);
  Return folder.DateLastModified;
}
function FolderDateCreated(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var folder = fso.GetFolder(path);
  Return folder.DateCreated;
}
function FileDateCreated(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var theFile = fso.Getfile(path);
  Return theFile.DateCreated;
}
function FileDateLastAccessed(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var theFile = fso.GetFile(path);
  Return theFile.DateLastAccessed;
}
function FileDateLastModified(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var theFile = fso.GetFile(path);
  Return theFile.DateLastModified;
}
function FileSize(path)
{
  Var fso  = CreateObject("COM", "Scripting.FileSystemObject");
  Var theFile = fso.GetFile(path);
  Return theFile.Size;
}

--/CFSCRIPT--

</head>

<cfset strFileName = ListLast(url.filename, "\")>
<cfset DirPath = Left(url.filename, Evaluate(Len(url.filename) - len(strFileName) - 1))>
<cfset TheFile = ListLast(url.filename)>
<cfset TheFolder = DirPath>

<body bgcolor="#617087" leftmargin=0 topmargin=0 marginwidth="0" marginheight="0">

<link rel="STYLESHEET" type="text/css" href="">
<br>
<p class="wdirlinks" align="center"><b>File Information</b>

<p class="wdirlinks">

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>

<td>
<table cellpadding="2" cellspacing="2" border="0">
<cfoutput>
<tr class="wdirlinks"><td width="70" align="right"><b>File:</b></td><td>#strFileName# created on #DateFormat(FileDateCreated(TheFile), 'mm/dd/yyyy')# at #TimeFormat
(FileDateCreated(TheFile), 'HH:MM:SS')#.</td></tr>
<tr class="wdirlinks"><td width="70">&nbsp;</td><td>last accessed on #DateFormat(FileDateLastAccessed(TheFile), 'mm/dd/yyyy')# at #TimeFormat
(FileDateLastAccessed(TheFile), 'HH:MM:SS')#</td></tr>
<tr class="wdirlinks"><td width="70">&nbsp;</td><td>last modified on #DateFormat(FileDateLastModified(TheFile), 'mm/dd/yyyy')# at #TimeFormat(FileDateLastModified
(TheFile), 'HH:MM:SS')#.</td></tr>
<tr class="wdirlinks"><td width="70" align="right"><b>Size:</b></td><td>#FileSize(TheFile)# bytes.</td></tr>

<tr class="wdirlinks"><td width="70" align="right"><b>Directory:</b></td><td>#TheFolder# created on #DateFormat(FolderDateCreated(TheFolder), 'mm/dd/yyyy')# at
#TimeFormat(FolderDateCreated(TheFolder), 'HH:MM:SS')#.</td></tr>
<tr class="wdirlinks"><td width="70">&nbsp;</td><td>last accessed on #DateFormat(FolderDateLastAccessed(TheFolder), 'mm/dd/yyyy')# at #TimeFormat
(FolderDateLastAccessed(TheFolder), 'HH:MM:SS')#.</td></tr>
<tr class="wdirlinks"><td width="70">&nbsp;</td><td>last modified on #DateFormat(FolderDateLastModified(TheFolder), 'mm/dd/yyyy')# at #TimeFormat
(FolderDateLastAccessed(TheFolder), 'HH:MM:SS')#.</td></tr>
<tr class="wdirlinks"><td width="70">&nbsp;</td><td>size of directory (including all files/subdirectories) is #FolderSize(TheFolder)# bytes.</td></tr>
</cfoutput>
</table>
</td>

</tr>
</table>


[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to