property textToFind : ""
property textToWrite : ""
property extensionList : {"html", "txt", "SFV"}
on run
set textToFind to text returned of (display dialog "Saisi le texte à rechercher : " default answer "" with icon 1)
set textToWrite to text returned of (display dialog "Saisi le texte de remplacement : " default answer "" with icon 1)
set theFolder to (choose folder)
processFolder(theFolder)
end run
-- traitement des fichiers
on processItem(thisitem)
set fileID to open for access file (thisitem as string)
set dataFromFile to read fileID as string
close access fileID
set dataToWrite to findReplace(dataFromFile, textToFind, textToWrite)
(* --boucle vérification--
set textOk to ""
set dataToWrite to dataToWrite as string
display dialog "datatowrite : " & dataToWrite
set nbrChar to (count of characters of (dataToWrite as string))
repeat with i from 1 to (nbrChar - 3)
set textOk to textOk & (character i of dataToWrite)
end repeat
display dialog "textok : " & textOk
*)
set x to open for access file (thisitem as string) with write permission
write dataToWrite to x
--write textOk to x
close access x
end processItem
--traitement des dossier
on processFolder(thisFolder)
set theseItems to list folder thisFolder without invisibles
repeat with i from 1 to count of theseItems
set thisitem to alias ((thisFolder as text) & (item i of theseItems))
set itemInfo to info for thisitem
if folder of itemInfo is true and package folder of itemInfo is false then
processFolder(thisitem)
else if (alias of itemInfo is false) and (the name extension of itemInfo is in extensionList) then
processItem(thisitem)
end if
end repeat
end processFolder
on findReplace(theData, toFind, replaceBy)
set text item delimiters to toFind
set theWords to {} & text items of theData
set theResult to 1st item of theWords
repeat with i from 2 to (length of theWords)
set theResult to theResult & replaceBy & (item i of theWords)
end repeat
return theResult
end findReplace