• 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
Re: Reading input from a delimited source file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Reading input from a delimited source file (From: Joseph Weaks <email@hidden>)

  • Prev by Date: Re: Localization
  • Next by Date: Re: Null
  • Previous by thread: Re: Reading input from a delimited source file
  • Next by thread: Handling Folders for Parent Path Reporting
  • Index(es):
    • Date
    • Thread