Reading a csv file
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