2012-10-03 92 views

回答

1
tell application "Finder" 
    set l to files of desktop as alias list 
end tell 
repeat with f in l 
    set input to read f as «class utf8» 
    set text item delimiters to "search" 
    set ti to text items of input 
    set text item delimiters to "replace" 
    set b to open for access f with write permission 
    set eof b to 0 
    write (ti as text) to b as «class utf8» 
    close access b 
end repeat 

我大多隻是用在項目中查找在TextMate中或Ruby腳本是這樣的:

Dir["#{ENV['HOME']}/Desktop/*"].each do |f| 
    input = File.read(f).gsub(/search/, "replace") 
    File.open(f, "w") { |f| f.print(input) } 
end 

您還可以使用SED:

sed -i '' 's/search/replace/g' ~/Desktop/*