Re: Reading input from a delimited source file
Re: Reading input from a delimited source file
- Subject: Re: Reading input from a delimited source file
- From: Bill White <email@hidden>
- Date: Wed, 08 Jan 2003 16:42:33 -0500
You're close. You're thinking of theSource as the contents of the file, but
you didn't "read" the contents into a variable.
Try this:
---------- Begin snippet ----------
property sourceFile : "Source.txt"
property sourcePath : (path to desktop as string) & sourceFile as string as
alias
set theSource to read sourcePath
set AppleScript's text item delimiters to (ASCII character 13)
set sourceList to text items of theSource
repeat with x from 1 to (length of sourceList)
set eachSource to item x of sourceList
-- do stuff with eachSource.
end repeat
----------- End snippet -----------
You can avoid the text item delimiters altogether like this:
property sourceFile : "Source.txt"
property sourcePath : (path to desktop as string) & sourceFile as string as
alias
set theSource to read sourcePath
repeat with x from 1 to (count paragraphs of theSource)
set eachSource to paragraph x of theSource
-- do stuff with eachSource.
end repeat
HTH,
Bill
>
-- Begin code snippet
>
Property sourceFile : "Source.txt"
>
>
set theSource to (open for access file ((path to desktop as string) &
>
sourceFile as string)
>
>
set AppleScript's text item delimiters to (ASCII character 13)
>
set sourceList to text items of theSource
>
>
repeat with x from 1 thru (length of sourceList)
>
set eachSource to item x of sourceList as string
>
-- do stuff with eachSource.
>
end repeat
>
>
close access theSource
>
-- End code
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.