Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFFILE Question

Status
Not open for further replies.

ColdFusionKing

Programmer
Dec 5, 2002
145
GB
Hello Everybody,

I want to see the contents of a directory on the
server. I know there is a function in CF to do this,
GetTemplatePath, cfdirectory or something (not sure).
The directory path will not change. I want to first
get to the directory and then find all log files in
the directory beginning with "SupportiSearches". There
are going to be more than one file with that name. The
idea is to append the contents of log files into one
log file.

To give you a better understanding, take for instance
there are 2 log files under the directory called:
Support2003-09.log and Support2003-08.log. I want to
read the contents stored in these files, both files
are identical in that the content is comma separated
and both files have the same no of columns. I want to
read the contents of the files using cffile and append
the contents stored in the files in one file. I hope
this is making sense. Can somebody please show me how
to do this.

Best Regards
Allan
 
Allan,

Have a look at this code:

<CFDIRECTORY ACTION=&quot;List&quot; DIRECTORY=&quot;#GetDirectoryFromPath(GetTemplatePath())#&quot; FILTER=&quot;SupportiSearches*.txt&quot; NAME=&quot;qry_getFiles&quot; SORT=&quot;Name ASC&quot;>

<CFSET FileWriteTo=&quot;AppendedFile.txt&quot;>

<CFLOOP QUERY=&quot;qry_getFiles&quot;>
<CFFILE ACTION=&quot;READ&quot; FILE=&quot;#GetDirectoryFromPath(GetTemplatePath())##qry_getFiles.Name#&quot; VARIABLE=&quot;file_content&quot;>

<CFIF Compare(file_content,&quot;&quot;) NEQ 0>
<!--- only write if there is something in the file --->
<CFFILE ACTION=&quot;APPEND&quot; FILE=&quot;#GetDirectoryFromPath(GetTemplatePath())##FileWriteTo#&quot; OUTPUT=&quot;#file_content#&quot; ADDNEWLINE=&quot;Yes&quot;>
</CFIF>
</CFLOOP>

I have assumed that the cfm file will be in the same directory as the log files that you are trying to access. At the moment the CFDIRECTORY is looking for files called SupportiSearches*.txt, i assume that the logfiles aren't a txt file ext so you will need to change that.

Also the cfdirectory is sorting by name, so an entry of SupportiSearches10, will appear before SupportiSearched2!

Hope this helps!

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top