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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF LOOP to Create Directories

Status
Not open for further replies.

coldfused

Technical User
Jan 27, 2001
2,442
US
I am using a loop to query a table and create directores from property names that have been stored. The problem is there are about 150 properties an it only seems to be creating about 75 of the directories. For whatever reason it does not complete. Here's the code:

Code:
<cfquery name="dirs" datasource="#dsn#">
  SELECT ID, Directory FROM property
</cfquery>
		
<cfloop query="dirs">
  <cfset propIndexSrc = "<cfset pagename='#dirs.Directory#'>
  <cfset isProperty=true>
  <cfset path = '../'>
  <cfset id = #dirs.ID#>
  <cfinclude template='##path##includes/masterinclude.cfm'>"> 
		
  <cfdirectory action="create" directory="#ExpandPath('../#dirs.Directory#')#" mode="777">

  <cffile action="write" output="#propIndexSrc#" file="#ExpandPath('../#dirs.Directory#/index.cfm')#">

</cfloop>

A couple of the fields are null, could that stop the loop from completing?

----------------------------------------
Internet Marketing - de·ci·phered
Always Learning...
 
Actually I should have tested before I posted, sorry. The solution was the Null fields were stopping the loop from completing.

For future reference if anyone runs into the same problem.

Fix:
Code:
<cfquery name="dirs" datasource="#dsn#">
  SELECT ID, Directory FROM property
</cfquery>
		
<cfloop query="dirs">
		
   <cfif dirs.Directory eq "">
				
   <cfelse>
   <cfset propIndexSrc = "<cfset pagename='#dirs.Directory#'>
   <cfset isProperty=true>
   <cfset path = '../'>
   <cfset id = #dirs.ID#>
   <cfinclude template='##path##includes/masterinclude.cfm'>"> 
		
   <cfdirectory action="create" directory="#ExpandPath('../#dirs.Directory#')#" mode="777">
   <cffile action="write" output="#propIndexSrc#" file="#ExpandPath('../#dirs.Directory#/index.cfm')#">
				
   </cfif>
				
</cfloop>

----------------------------------------
Internet Marketing - de·ci·phered
Always Learning...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top