jrottman
Programmer
- Jun 17, 2005
- 47
I have setup a controlled test. In my directory structure, I have the following folders.
AD
PC
SPDS
Inside each of those folders, I have placed, text files. So I get a final structure like this
AD
file.txt
PC
file.txt
file.txt
file.txt
SPDS
file.txt
file.txt
The issue I have is, I am trying to turn this directory listing into an array of strcutures. It looks like this. This is somewhat correct, but for each structure it should show the total number of records for each directory. IE. The PC Struct should have 3 records underneath it instead of just one, because there are 3 files inside that folder. AD is correct and should only have one, beacuse there is only one file, and SPDS should hve 2 records because there are 2 files inisde that folder.
Here is the code I am testing with.
<cfdirectory action="list" recurse="yes" directory="#APPLICATION.storePath##APPLICATION.systemInfo.fld_officeCode#/L060001" name="ListDir" />
<cfquery name="ListDirQry" dbtype="query">
select * from ListDir
where type = 'Dir'
</cfquery>
<cfset dirArray = arrayNew(1)>
<cfset dcounter = 1>
<cfset fcounter = 1>
<cfloop query="ListDirQry">
<cfset dirArray[dcounter] = structnew()>
<cfset dirArray[dcounter].dir = ListDirQry.name>
<cfquery name="ListFileQry" dbtype="query">
select * from ListDir
where type = 'File' and directory = '#APPLICATION.storePath##APPLICATION.systemInfo.fld_officeCode#/L060001/#dirArray[dcounter].dir#'
</cfquery>
<cfloop query="ListFileQry">
<cfset dirArray[dcounter].file = ListFileQry.name>
<cfset fcounter = fcounter + 1>
</cfloop>
<cfset dcounter = dcounter + 1>
</cfloop>
<cfdump var="#dirArray#" />
AD
PC
SPDS
Inside each of those folders, I have placed, text files. So I get a final structure like this
AD
file.txt
PC
file.txt
file.txt
file.txt
SPDS
file.txt
file.txt
The issue I have is, I am trying to turn this directory listing into an array of strcutures. It looks like this. This is somewhat correct, but for each structure it should show the total number of records for each directory. IE. The PC Struct should have 3 records underneath it instead of just one, because there are 3 files inside that folder. AD is correct and should only have one, beacuse there is only one file, and SPDS should hve 2 records because there are 2 files inisde that folder.
Here is the code I am testing with.
<cfdirectory action="list" recurse="yes" directory="#APPLICATION.storePath##APPLICATION.systemInfo.fld_officeCode#/L060001" name="ListDir" />
<cfquery name="ListDirQry" dbtype="query">
select * from ListDir
where type = 'Dir'
</cfquery>
<cfset dirArray = arrayNew(1)>
<cfset dcounter = 1>
<cfset fcounter = 1>
<cfloop query="ListDirQry">
<cfset dirArray[dcounter] = structnew()>
<cfset dirArray[dcounter].dir = ListDirQry.name>
<cfquery name="ListFileQry" dbtype="query">
select * from ListDir
where type = 'File' and directory = '#APPLICATION.storePath##APPLICATION.systemInfo.fld_officeCode#/L060001/#dirArray[dcounter].dir#'
</cfquery>
<cfloop query="ListFileQry">
<cfset dirArray[dcounter].file = ListFileQry.name>
<cfset fcounter = fcounter + 1>
</cfloop>
<cfset dcounter = dcounter + 1>
</cfloop>
<cfdump var="#dirArray#" />