Skip to content

Instantly share code, notes, and snippets.

@slacken
Created December 12, 2012 07:55
Show Gist options
  • Select an option

  • Save slacken/4265928 to your computer and use it in GitHub Desktop.

Select an option

Save slacken/4265928 to your computer and use it in GitHub Desktop.
replace all php file's content in current dir with Ruby
#encoding:utf-8
def startdir(dir)
Dir.foreach(dir){|file|
next if file[0] == '.'
path = dir+file
if File.directory?(path)
startdir(path+'/')
next
end
next unless file[-4,4] == '.php'
content = File.read(path)
if content.include?('聚摊网')
content['聚摊网'] = '聚城'
puts path+":#{content.size}"
File.write(path,content)
end
}
end
startdir('./')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment