URL to Variables

Ok...I closed my first question too soon it appear.

What I need to do is take a url for example www.mysite.com/directory1/directory2/directory3/ and making each directory a variable.   Below is the code that kind of does what I need:

<cfset url1 = "http://www.mywebsite.com/d1/d2/d3/">
<cfset dir_num = 0>


<cfloop condition = "dir_num less than 3">
     <cfset first_slash = 0>
     <cfset second_slash = 1>
     <cfset ind = 1>
     <cfloop condition="ind less than or equal to len(url1)">
          <cfif #Mid(url1, ind, 1)# eq "/">
               <cfset first_slash = #second_slash#>
               <cfset second_slash = #ind#>
          </cfif>
          <cfset ind = #ind# + 1>  
     </cfloop>
     <cfset length = #second_slash# - #first_slash# - 1>
     <cfset directory = Mid(#url1#, #first_slash#+1, #length#)>

     <cfswitch expression="#dir_num#">
       <cfcase value="0">
         <cfset directory3 = #directory#>
       </cfcase>
       <cfcase value="1">
         <cfset directory2 = #directory#>
       </cfcase>
       <cfcase value="2">
         <cfset directory1 = #directory#>
       </cfcase>
     </cfswitch>

     <cfset url1 = Mid(url1,1,len(url1)-#length#-1)>

     <cfset dir_num = #dir_num# + 1>
</cfloop>

<cfoutput>
d1 = #directory1#
d2 = #directory2#
d3 = #directory3#
</cfoutput>

I need this code to do a couple more things:
1. if there is a file specified ignore it....I just want the directories returned as variables
2. only define variables for directories defined for example if the site is www.mysite.com/directory1/directory2/  there will only be two variables defined ...if there are 3 directories...3 variables will be defined.  
3. completely ignore the host...I do not need this returned as a variable...
mhixonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ftvcsCommented:
You should see the url string as a list, separated with '/'.
If a file is specied, :

<cfset urlarray = arrayNew(1)>
<cfset c=0>
<cfloop index = "index_name"    list = "#url1#"    delimiters = "/">
<cfif not index_name contains ".">
   <cfset urlarray[c]=index_name>
   <cfset c=c+1>
</cfif>
</cfloop>

<cfdump var="#urlarray#">
0
mhixonAuthor Commented:
I get the following error:

The element at position 0 of array variable &quot;URLARRAY&quot; cannot be found.
0
Tacobell777Commented:
<cfset variables.url1 = "http://www.mywebsite.com/d1/d2/d3/" />
<cfset variables.dir_num = 0 />

<cfloop
      index="item"
      list="#variables.url1#"
      delimiters="/">

      <cfset variables.dir_num = variables.dir_num + 1 />
      <cfset structInsert( variables, "directory" & variables.dir_num, variables.item ) />

</cfloop>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

mhixonAuthor Commented:
I get the following error:

Cannot insert item with key directory1.  
 This key already exists.  
0
mhixonAuthor Commented:
Sorry about that...my error...got it to work....Im going to work with this a little bit and make sure it does everything I need it to....Ill be back in touch thanks
0
mhixonAuthor Commented:
Thanks...got this to do everything I want....appreciate the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.