• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Reading a csv file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading a csv file


  • Subject: Reading a csv file
  • From: Ian Cook <email@hidden>
  • Date: Wed, 9 Feb 2005 09:40:34 +0000

Hi, I'm trying to read in a csv file into a list array in my applescript. I've achieved it using a TAB delimited file, but with a comma delimited file, any commas within a text item are being treated as item delimiters too. Therefore...

453.25, "Large, red car"

is being read as three items rather than two. I'm thinking that as the second item is in quotes there should be some syntax I can use to get around the problem?

The script is being implemented as a droplet on a lot of machines within a large organisation so I want to keep the scripting standard, avoiding using any additions or databases.

Here's my script for reading from a TAB delimited file...

--select the data.txt file within the folder
on open (theFolder)
set theFile to ((theFolder as text) & "data.txt") as alias

set old_delimiters to AppleScript's text item delimiters

--read every line as item
set AppleScript's text item delimiters to ASCII character 13
set myData to every text item of (read theFile)

set AppleScript's text item delimiters to ASCII character 9
set myArray to {}
repeat with x in myData
	set myArray to myArray & {every text item of x}
end repeat

Thanks for any suggestions
Ian Cook

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Reading a csv file
      • From: Andrew Oliver <email@hidden>
  • Prev by Date: Re: Re: A question on shell scripting in AppleScript (Applescript-users Digest, Vol 2, Issue 91)
  • Next by Date: where are the shell scripts ?
  • Previous by thread: Re: A question on shell scripting in AppleScript (Applescript-users Digest, Vol 2, Issue 91)
  • Next by thread: Re: Reading a csv file
  • Index(es):
    • Date
    • Thread