Le 6 oct. 2010 à 16:58, Richard Lake a écrit : Hi,
Jon Pugh's example works perfect fine by itself when declaring the array in applescript:
set formData to {{"Customer GUID", "Form GUID", "Contact GUID", "Form Type", "Ref No", "Account Number", "Company Name", "Contact Name", "Contact Address", "Email address", "Artwork awaiting Response", "Days no Response", "Special Pricing", "Date"}, {"7C925871-2545-458E-9E1A-F3362F5010BE", "CFB29657-ABBA-4AAC-83CF-F436D1AFE3BE", "2ADC20E6-6AB3-4FD9-B137-BAD34D1B580D", "QT", "", "C0067C", "Conocophillips", "A Name", "An Address[]2nd Line[]3rd Line[]Etc[]", "email@address", "No", "1", "No", ""}, {"7C925871-2545-458E-9E1A-F3362F5010BE", "97A6977D-B0F4-480B-ACA5-9977E7307996", "2CAC23D0-AEF7-4194-AD1C-201B053298A0", "SO", "3111", "C0067C", "Conocophillips", "A Name", "An Address[]2nd Line[]3rd Line[]Etc[]", "aemail@address", "No", "1", "No", ""}, {"059B2178-D55B-4542-A794-0B4079F6B007", "C6484FD1-989C-4DA5-8AF8-161769BB1146", "5734F334-2851-496A-82D0-B6A7658ACA53", "SO", "3112", "B0063C", "Exova", "A Name", "An Address[]2nd Line[]3rd Line[]Etc[]", "email@address", "Yes", "1", "Yes", ""}}
But when I try and read the data externally from a .csv file it pads quotations mark as \" so when quickSort is called it doesn't understand how to process the file. I've tried parsing or using applescript delimiters with no success.
on readFile(unixPath, posix) if posix = yes then set foo to (open for access unixPath) else if posix = no then set foo to (open for access (POSIX file unixPath)) end if
set txt to (read foo for (get eof foo))
close access foo
return txt end readFile
on readguidtable() set formData to readFile((POSIX path of (path to scripts folder) as text) & "formdb.csv", no) set formCount to count paragraphs of formData set formentries to paragraphs of formData -- << how do i read the damn csv in correctly and make it into a bloody array structure... >.< end readguidtable
reverse of quickSort({Values:formentries, Weights:{5}})
CSV file example:
"Customer GUID","Form GUID","Contact GUID","Form Type","Ref No","Account Number","Company Name","Contact Name","Contact Address","Email address","Artwork awaiting Response","Days no Response","Special Pricing","Date" "17F1098A-482E-4BCB-BC17-B56094FF7CC1","ADB3CC97-0A42-40FF-9C63-10AB043A0F7E","66864065-0256-41E3-AFCF-CC7053DAD196","PF","","S0154C","Synectic Systems Group Ltd","A Name","","email@address","Yes","2","No","" "43C79C66-2127-41B9-B444-34EAB49DEB68","7AF809BA-10F9-4997-858D-DF3ACE829BC0","ED9FF7CF-ECF0-4D2D-BAB9-687B4AEEF109","QT","2940","M0012C","Manchester Metropolitan University[] The","A Name","An Address[]2nd Line[]3rd Line[]Etc[]","email@address","No","1","No","" "41A9C623-3E6E-44E1-81D6-FC5B57FCC7D8","4625DC32-B013-42CC-BFD4-73962A3106F4","1D54FDFE-731E-4B85-BD7B-416A7B05AA90","SO","3110","C0250C","Chem-dry (uk) Ltd","A Name","An Address[]2nd Line[]3rd Line[]Etc[]","email@address","Yes","2","No",""
I want this to be read into an array as per the 'set formData code'.
I would do that this way :
on run
set le_fichier to "" & (path to desktop) & "uncsv.csv"
set une_liste to paragraphs of (read file le_fichier)
repeat with une_ref in une_liste set contents of une_ref to my decoupe(text 2 thru -2 of contents of une_ref, quote & "," & quote) end repeat une_liste end run
--=====
on decoupe(t, d) local oTIDs, l set oTIDs to AppleScript's text item delimiters set AppleScript's text item delimiters to d set l to text items of t set AppleScript's text item delimiters to oTIDs return l end decoupe
--=====
Yvan KOENIG (VALLAURIS, France) mercredi 6 octobre 2010 18:18:34
|