Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

segregating a list into two lists

Posted on 2016-07-22
4
Medium Priority
?
113 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
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 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