?
Solved

CFDirectory reading all files on a website.

Posted on 2006-06-10
4
Medium Priority
?
310 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 600 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 600 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 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