Solved

CFDirectory reading all files on a website.

Posted on 2006-06-10
4
286 Views
Last Modified: 2013-12-24
Okay.. I have been fiddling with this for a while, and cannot figure out why it only gives me output for one page on my website.

<!---This loop collects all the files into one list--->
<cfset name = "PageIndex">
<cfset FileList = "">
<cfloop list="E:\Inetpub\websitename\public_html\" index="Dir">
  <cfdirectory
   action = "list"
   directory = "#Dir#"
   name = "IndexList"
   filter = "*.html">
  <cfoutput query="IndexList">
    <cfif IndexList.type is "file">
      <cfset FileList = listappend(FileList,Dir&IndexList.name)>
    </cfif>
  </cfoutput>
</cfloop>
<cfloop list="#FileList#" index="ParseFile">
  <CFFILE ACTION="READ" file="#ParseFile#" variable="str">
  <!---Extra the TITLE meta tag--->
  <cfset startstring="<TITLE>">
  <cfset endstring="</TITLE>">
  <cfset parsed="">
  <CFSET start = findnocase(startstring,str)+len(startstring)>
  <cfif start lt 1>
    <cfset start=1>
  </cfif>
  <cfset end = findnocase(endstring,str,start)>
  <cfif end gt start>
    <cfset parsed = trim(MID(str,start,end-start))>
  </cfif>
  <!--Extract the Description meta tag--->
  <cfset startstring2="<meta name=#chr(34)#description#chr(34)# content=#chr(34)#">
  <cfset endstring2="#chr(34)#">
  <cfset parsed2="">
  <CFSET start2 = findnocase(startstring2,str)+len(startstring2)>
  <cfif start2 lt 1>
    <cfset start2=1>
  </cfif>
  <cfset end2 = findnocase(endstring2,str,start2)>
  <cfif end2 gt start2>
    <cfset parsed2 = trim(MID(str,start2,end2-start2))>
  </cfif>
  <!---Extra the BODY meta tag--->
  <cfset startstring3="<BODY">
  <cfset endstring3="</BODY>">
  <cfset parsed3="">
  <CFSET start3 = findnocase(startstring3,str)+len(startstring3)>
  <cfif start3 lt 1>
    <cfset start3=1>
  </cfif>
  <cfset end3 = findnocase(endstring3,str,start3)>
  <cfif end3 gt start3>
    <cfset parsed3 = trim(MID(str,start3,end3-start3))>
  </cfif>
</cfloop>

<cfoutput>#parsed#<BR>
  #parsed2#<BR>
  #parsed3#</cfoutput>
0
Comment
Question by:ServalStudios
4 Comments
 
LVL 10

Accepted Solution

by:
js_vaughan earned 150 total points
ID: 16879020
Shouldn't your <cfoutput> at the bottom of the page be inside your loop?
0
 
LVL 25

Assisted Solution

by:dgrafx
dgrafx earned 150 total points
ID: 16880910
I modified it for you:
<!---This loop collects all the files into one list--->
<!--- <cfset name = "PageIndex"> Don't need this --->
<cfset FileList = "">
<cfloop list="d:\_web\_cfitools\" index="Dir">
  <cfdirectory
   action = "list"
   directory = "#Dir#"
   name = "IndexList"
   filter = "*.html">
  <cfoutput query="IndexList">
    <cfif IndexList.type is "file">
      <cfset FileList = listappend(FileList,Dir&IndexList.name)>
    </cfif>
  </cfoutput>
</cfloop>
<!--- <cfoutput>#filelist#</cfoutput><CFABORT> --->
<cfloop list="#FileList#" index="ParseFile">
<CFFILE ACTION="READ" file="#ParseFile#" variable="str">
  <!---Extract the TITLE meta tag--->
      <cfset startstring="<TITLE>">
      <cfset endstring="</TITLE>">
      <cfset parsed="">
      <CFSET start = findnocase(startstring,str)>
      <cfif start>
            <cfset start=start+len(startstring)>
            <cfset end = findnocase(endstring,str,start)>
            <cfif end gt start>
            <cfset parsed = trim(MID(str,start,end-start))>
            </cfif>
      </cfif>
  <!--Extract the Description meta tag--->
      <cfset startstring2="<meta name=#chr(34)#description#chr(34)# content=#chr(34)#">
      <cfset endstring2="#chr(34)#">
      <cfset parsed2="">
      <CFSET start2 = findnocase(startstring2,str)>
      <cfif start2>
            <cfset start2=start2+len(startstring2)>      
            <cfset end2 = findnocase(endstring2,str,start2)>
            <cfif end2 gt start2>
            <cfset parsed2 = trim(MID(str,start2,end2-start2))>
            </cfif>
      </cfif>
      <!---Extra the BODY meta tag--->
      <cfset startstring3="<BODY">
      <cfset endstring3="</BODY>">
      <cfset parsed3="">
      <CFSET start3 = findnocase(startstring3,str)>
      <cfif start3>
            <cfset start3=start3+len(startstring3)>      
            <cfset end3 = findnocase(endstring3,str,start3)>
            <cfif end3 gt start3>
            <cfset parsed3 = trim(MID(str,start3,end3-start3))>
            </cfif>
      </cfif>
This is your output here - for your <body> tag you will probably need htmlcodeformat to "see" it or htmleditformat to insert to db<br>
<cfoutput>
#parsed#<BR>
#parsed2#<BR>
#parsed3#<br><br>
</cfoutput>

</cfloop>

0
 
LVL 2

Expert Comment

by:pharmacychoice
ID: 16889618
You are only getting output for one page because of what js_vaughn said.  You need to have your cfoutput in the cfloop or else you are only getting the one record.
0
 
LVL 1

Author Comment

by:ServalStudios
ID: 16891939
Thank you.!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question