Skip to content

Instantly share code, notes, and snippets.

@willwade
Forked from craigeley/batch_pandoc.rb
Created November 16, 2017 13:29
Show Gist options
  • Save willwade/a719f1db4ac0f31199e4f7d75435a4e2 to your computer and use it in GitHub Desktop.
Save willwade/a719f1db4ac0f31199e4f7d75435a4e2 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