• 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: Read for 1000 until nearest space?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Read for 1000 until nearest space?


  • Subject: Re: Read for 1000 until nearest space?
  • From: Paul Berkowitz <email@hidden>
  • Date: Tue, 14 Oct 2008 02:23:41 -0700
  • Thread-topic: Read for 1000 until nearest space?

On 10/14/08 12:14 AM, "Joe" <email@hidden> wrote:

> At 8:41 PM -0700 10/13/08, Philip Aker wrote:
>> Seems like it has to be a composite operation:
>>
>> set p2d to (path to desktop folder as text)
>> set fpath to p2d & "aaa.txt"
>> try
>> set fd to open for access fpath
>> set d1 to read fd for 50
>> set d2 to read fd until space
>> close access fd
>> set res to d1 & d2
>> {res, length of res}
>> on error
>> try
>> close access fd
>> end try
>> end try
>
> I thought that was going to do it, but trying to read through the remainder
> of the file failed with the script returning only the first ~n characters
> repeatedly
> without setting pointers and progressing on through the file.
>
> --I tried
> set p2d to (path to desktop folder as text)
> set fpath to p2d & "aaa.txt"
> try
>  repeat
>   set fd to open for access fpath
>   set d1 to read fd for 1000
>   set d2 to read fd until space
>   --close access fd
>   set res to d1 & d2
>   set x to {res, length of res}
>   display dialog x as string
>  end repeat
> on error
>  try
>   close access fd
>  end try
> end try
>
That's because you're continually opening for access, which starts from the
beginning of the file each time. Put that line before the repeat block:


set p2d to (path to desktop folder as text)
set fpath to p2d & "aaa.txt"

set fd to open for access alias fpath
try
    repeat
        set d1 to read fd for 1000
        set d2 to read fd until space
        set res to d1 & d2
        set x to {res, length of res}
        display dialog x as string
    end repeat
on error
    try
        close access fd
    end try
end try





--
Paul Berkowitz


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Read for 1000 until nearest space? (From: Joe <email@hidden>)

  • Prev by Date: Re: Need Script To Copy User Folder to External Drive
  • Next by Date: Photoshop - positionning layers
  • Previous by thread: Re: Read for 1000 until nearest space?
  • Next by thread: Need Script To Copy User Folder to External Drive
  • Index(es):
    • Date
    • Thread