Solved

CFDirectory reading all files on a website.

Posted on 2006-06-10
4
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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