Skip to content

Instantly share code, notes, and snippets.

@craigeley
Created June 11, 2014 15:18
Show Gist options
  • Save craigeley/bf189da1de3c70753cea to your computer and use it in GitHub Desktop.
Save craigeley/bf189da1de3c70753cea to your computer and use it in GitHub Desktop.
Batch convert files in a folder with Pandoc
#!usr/bin/ruby
# Change the file extensions below with what you are converting from and to
extFrom = '.html'
extTo = '.md'
files = Dir.glob("*#{extFrom}")
name = ''
base = ''
files.each do |file|
if File.exists?(file.strip)
f = File.open(file.strip, encoding: 'UTF-8')
name = File.basename(file)
base = File.basename(file).gsub(/#{extFrom}/, '')
command = "pandoc " + "#{name}" + " -o " + "#{base}" + "#{extTo}"
%x{#{command}}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment