Skip to main content
Inspiring
July 13, 2006
Question

Import a comma text file with CF 5

  • July 13, 2006
  • 1 reply
  • 308 views
I have a comma delimted text file with a bunch of records.... each field enclosed in quotes like :

"stuff","stuff","stuff"
"stuff","stuff","stuff"
"stuff","stuff","stuff"
"stuff","stuff","stuff"
etc...


- I'm using cffile action= READ xxxxxx variable="getstuff" - to get the data
- now i want to loop thru and import all the records into the proper fields into a pre existing table...

Q: what the easiest way to loop thru and import these records?


I'm trying things like :


cfloop index="this"
list="#get#"
delimiters="#chr(13)##chr(10)#"

field 1 = ListGetAt(this, 1)
field 2 = ListGetAt(this, 2)
etc..

but maybe there's a better way?
    This topic has been closed for replies.

    1 reply

    Inspiring
    July 13, 2006
    <!--- loop throu the file to get each row --->
    <cfloop index="rowElement" list="#getstuff#" delimiters="="#chr(13)##chr(10)#">

    <!--- then loop through each row to get the elements --->
    <cfloop index="indElement" list="#rowElement#" delimiters="=",">
    <!--- note each element will be enclosed in quotes --->
    <cfoutput>#indElement#</cfoutput>

    </cfloop>
    </cfloop>

    Ken
    Participating Frequently
    July 13, 2006
    Much faster way is to use ListToArray() first and to loop thru array elements. ListGetAt() is very slow.