Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion - cfdirectory sort order question

Posted on 2013-05-16
4
Medium Priority
?
654 Views
Last Modified: 2013-05-17
I have folder with images named like A199250-1.jpg,  A199250-2.jpg, A199250-11.jpg, etc...Each image name has a corresponding property listing id like: "A199250"

The problem is trying to sort these in the correct order.
Here is how they currently sort:
A199250-1.jpg
A199250-11.jpg
A199250-2.jpg



I need them to sort like:
A199250-1.jpg
A199250-2.jpg
A199250-11.jpg

<cfdirectory action="list" directory="#ExpandPath('/ftp/rets/photos/')#" filter="#variables.IDnumber#*" name="files" sort = "directory ASC">

Can someone have a look at my code and tell me how to accomplish this? Thanks!
0
Comment
Question by:Bang-O-Matic
[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
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39172136
There's no slick way to do this.  If QoQ's supported basic string functions like mid() etc.., you could do it in a single query. But QoQ's don't support those functions. So that's not an option.

What you could do is add 2 columns to the cfdirectory query object:

<!--- add new columns for sorting --->
<!--- for older versions, use ArrayNew(1) instead of "[]" --->
<cfset queryAddColumn(qList, "fileID", []) />
<cfset queryAddColumn(qList, "fileNumber", []) />

Then use a loop to split out the "id" and file "number"

<cfset delims = "-.">
<cfloop query="qList">
      <cfif listLen(qList.name, delims) eq 3>
            <!--- extract file id and counter *number* --->
            <cfset qList.fileID[currentRow] = getToken(qList.name, 1, delims)>
            <cfset qList.fileNumber[currentRow] = val(getToken(qList.name, 2, delims))>
      </cfif>
</cfloop>

Finally resort the results by the "id" then "number"

<!--- resort by id, then counter number --->
<cfquery name="qList" dbtype="query">
      SELECT *
      FROM   qList
      ORDER BY fileID, fileNumber, name
</cfquery>

<cfdump var="#qList#">

It's lame, but it works :)
0
 

Author Comment

by:Bang-O-Matic
ID: 39172636
Hi _agx_,

I did some research myself before posting so I knew it would not be simple to solve. :(
How would you work that code into my existing code? (This code runs on a property detail page and loads images into a slider based on the ListID.) Thanks for the help!

<cfset variables.IDnumber = #URL.ListID#>

<cfdirectory action="list" directory="#ExpandPath('/ftp/rets/photos/')#" filter="#variables.IDnumber#*" name="files" sort = "directory ASC">
       <cfif files.recordCount eq 0>
             
   <img src="../images/no-photo.png"  alt="no-photo" />

                  <cfelse>

       <cfloop query="files">
     
     <a class="rsImg" data-rsh="500" data-rsBigImg="/ftp/rets/photos/#files.name#" href="/ftp/rets/photos/#files.name#">
     <img width="96" height="72" class="rsTmb" src="/ftp/rets/photos/#files.name#" /></a>
     
    </cfloop>
    </cfif>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 39172908
I'd probably throw the whole thing into a function that does the filtering and returns a query. Then call the function instead of <cfdirectory>. Everything else would be the same

Usage: (Call this instead of cfdirectory)

<cfset files = getListingsByID( ExpandPath('/ftp/rets/photos/'), URL.ListID )>

Function (Double check that everything's VAR scoped)
<cffunction name="getListingsByID" returntype="query">
	<cfargument name="directoryPath" type="string">
	<cfargument name="idNumber" type="string">

	<cfset var delims = delims = "-." />
	<cfset var qList = delims = "-." />
	
	<cfdirectory action="list" 
			directory="#arguments.directoryPath#" 
			filter="#arguments.idNumber#*" 
			name="qList" 
			sort="directory ASC">	

	<cfset queryAddColumn(qList, "fileID", []) />
	<cfset queryAddColumn(qList, "fileNumber", []) />

	<cfloop query="qList">
		<cfif listLen(qList.name, delims) eq 3>
			<!--- extract file id and counter *number* --->
			<cfset qList.fileID[currentRow] = getToken(qList.name, 1, delims)>
			<cfset qList.fileNumber[currentRow] = val(getToken(qList.name, 2, delims))>
		</cfif>
	</cfloop>

	<!--- resort by id, then counter number --->
	<cfquery name="qList" dbtype="query">
		SELECT *
		FROM   qList
		ORDER BY fileID, fileNumber, name
	</cfquery>

	<cfreturn qList />
</cffunction>

Open in new window

0
 

Author Closing Comment

by:Bang-O-Matic
ID: 39174820
Excellent solution that worked perfectly! Thank you _agx_ !
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

715 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