Re: replacing text
Re: replacing text
- Subject: Re: replacing text
- From: "Marc K. Myers" <email@hidden>
- Date: Thu, 14 Jun 2001 05:17:21 -0400
- Organization: [very little]
>
Date: Wed, 13 Jun 2001 16:32:55 -0400
>
From: g_vkatta <email@hidden>
>
Subject: replacing text
>
To: applescript-users <apples email@hidden>
>
>
hi!
>
>
i have a folder consisisting of html files,i want to delete a line in all the
>
html files in side that folder,i can do it manually by opening each file and
>
deleting the same line in each file in side that folder.
>
>
can some one plesae provide me with the script that selects the folder
>
consisting of many html files and deletes the text in all the html files at a
>
stretch.
This is untested, but it ought to work. Where you see "[optn-L]",
substitute the AppleScript continuation character (obtained with that
keyboard combination).
property textToDelete : "put the string here"
set theFolder to (choose folder with prompt "Select the folder:")
tell application "Finder"
set fileList to [optn-L]
(files of theFolder whose file type is "TEXT") as alias list
end tell
repeat with aFile in fileList
set fileID to (open for access (contents of aFile) with write permission)
try
set theText to read fileID
set {od, AppleScript's text item delimiters} to [optn-L]
{AppleScript's text item delimiters, {textToDelete}}
set theText to text items of theText
set AppleScript's text item delimiters to od
set theText to (theText as text)
set eof fileID to 0
write theText to fileID starting at eof
close access fileID
on error m number n
try
close access fileID
end try
error m number n
end try
end repeat
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[6/14/01 5:13:32 AM]