Re: find a string in a file
Re: find a string in a file
- Subject: Re: find a string in a file
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 23 May 2003 12:45:53 -0700
On 5/23/03 12:09 PM, "Ruby Madraswala" <email@hidden> wrote:
>
I am trying to process files that contains "%%" and the simple test script
>
does not work. (running on OS 9.2.2).
The script works perfectly. It's the scripter that's getting things wrong.
You're not asking for what you want.
>
>
Set efile to "EEHD:efile9.txt"
eFile is just a string: "EEHD:efile9.txt". There's no "%%" anywhere in that
string , is there? So the script is perfectly correct in not finding it
there. You need to refer to
alias "EEHD:efile9.txt"
if you mena the file. And then you need to read the file, which is easy
enough.
>
If efile contains "%%" then
>
Display dialog "Found"
>
End if
What you mean, I think, is this:
set eFile to alias "EEHD:efile9.txt" -- that's a file
set fileText to read eFile -- that gets the content of a file
if fileText contains "%%" then
display dialog "Found"
else
display dialog "Not there."
end if
This will error if you text is larger than 32K bytes, because AppleScript
can't do string comparisons ('contains') on strings larger than 32K. You'll
have to do something like this for that case:
set eFile to alias "EEHD:efile9.txt"
set fileText to read eFile
set start to 1
set done to false
repeat until done
try
set aChunk to text start thru (start + 30000) of fileText
on error -- last chunk
set aChunk to text start thru -1 of fileText
set done to true -- won't repeat again
end try
if aChunk contains "%%" then
display dialog "Found"
return -- finish script now
else
set start to start + 30000
end if
end repeat
display dialog "Not there" -- doesn't appear if found
end try
>
Also tried
>
Set efile to "EEHD:efile9.txt"
>
Set SrhText to "%%"
>
If efile contains SrhText then
>
Display dialog "Found"
>
End if
Same problem.
--
Paul Berkowitz
_______________________________________________
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.