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

x
?
Solved

segregating a list into two lists

Posted on 2016-07-22
4
Medium Priority
?
104 Views
Last Modified: 2016-07-24
Hi I have the following list

D:\inetpub\wwwroot\July-2016\overview\05572YEF5.pdf D:\inetpub\wwwroot\July-2016\overview\45083AFX5.pdf D:\inetpub\wwwroot\July-2016\overview\46176PFG5.pdf D:\inetpub\wwwroot\July-2016\overview\38148DLN2.pdf D:\inetpub\wwwroot\July-2016\overview\38148DLQ5.pdf D:\inetpub\wwwroot\July-2016\overview\94986TA23.pdf D:\inetpub\wwwroot\March-2016\overview\FocusList.pdf D:\inetpub\wwwroot\March-2016\overview\38148DHS6.pdf D:\inetpub\wwwroot\March-2016\overview\38148DHK3.pdf D:\inetpub\wwwroot\March-2016\overview\38148DHV9.pdf 

Open in new window


I want to create the seperate lists for both, now tthere is a small catch. the July-2016 and March-2016 will be dynamic values i mean they can from jan or feb or 2015 so a single can contain multiple month and years combination.

i want them to be created as seperate lists so i can use them

how can i do, i tried few of the functions like listvenn or listcompare, none seems to matching what i am trying to do here from cflib
0
Comment
[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 39

Expert Comment

by:gdemaria
ID: 41725319
You want to create two lists based on the value of the month-year?

First, loop through the file paths and pull out the fourth value which is the month/year
Create a structure whose elements are those dates, then add the file path to that structure.

<cfset newList = structNew()>
<cfloop index="aPath" list="#string#" delimiters=" ">
   <cfset theDate = listGetAt(aPath,4,"\/")>
   <cfif NOT structKeyExists(newList,theDate)>
      <cfset newList[theDate] = thePath>
   <cfelse> <!---- key already exists ---->
      <cfset newList[theDate] = listAppend(newList[theDate],thePath," ")>
   </cfif>
</cfloop>

<cfdump var="#newList#">

Open in new window

0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 41725402
ok, i tried running this and got error

first: what is string referred to: is it my list which i shared in the question

and 2. what is thePath, i am getting error on that
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 total points
ID: 41725417
the string is the list of paths you have.

ThePath is a type o, it is the same variable in the index

<cfset newList = structNew()>
<cfset theString = "D:\inetpub\wwwroot\July-2016\overview\05572YEF5.pdf D:\inetpub\wwwroot\July-2016\overview\45083AFX5.pdf D:\inetpub\wwwroot\July-2016\overview\46176PFG5.pdf D:\inetpub\wwwroot\July-2016\overview\38148DLN2.pdf D:\inetpub\wwwroot\July-2016\overview\38148DLQ5.pdf D:\inetpub\wwwroot\July-2016\overview\94986TA23.pdf D:\inetpub\wwwroot\March-2016\overview\FocusList.pdf D:\inetpub\wwwroot\March-2016\overview\38148DHS6.pdf D:\inetpub\wwwroot\March-2016\overview\38148DHK3.pdf D:\inetpub\wwwroot\March-2016\overview\38148DHV9.pdf">
<cfloop index="aPath" list="#theString#" delimiters=" ">
   <cfset theDate = listGetAt(aPath,4,"\/")>
   <cfif NOT structKeyExists(newList,theDate)>
      <cfset newList[theDate] = aPath>
   <cfelse> <!---- key already exists ---->
      <cfset newList[theDate] = listAppend(newList[theDate],aPath," ")>
   </cfif>
</cfloop>

<cfdump var="#newList#">

Open in new window

0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 41726554
Thanks for the quick response and good answer.
0

Featured Post

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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