Skip to content

Instantly share code, notes, and snippets.

@nmische
Created May 27, 2014 15:00
Show Gist options
  • Save nmische/93b8c77455570284afa3 to your computer and use it in GitHub Desktop.
Save nmische/93b8c77455570284afa3 to your computer and use it in GitHub Desktop.
A script to convert files to UTF-8.
new File('~/tmp').eachFile {
def toolkit = new CharsetToolkit(it)
def cs = toolkit.getCharset().toString()
def filePath = it.path + '/' + it.name
println filePath + ': ' + cs
if (cs != 'UTF-8') {
def content = it.getText(cs)
it.write(content ,'UTF-8')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment