0
我有一大堆生活在一個文件夾中的html文件。我需要將這些轉換爲降價,我發現了一個很棒的寶石,一個接一個。 我的問題是... 如何循環瀏覽文件夾中的每個文件,然後運行命令將它們轉換爲獨立文件夾中的md。批量轉換HTML到Markdown
UPDATE
#!/usr/bin/ruby
root = 'C:/Doc'
inDir = File.join(root, '/input')
outDir = File.join(root, '/output')
extension = nil
fileName = nil
Dir.foreach(inDir) do |file|
# Dir.foreach will always show current and parent directories
if file == '.' or item == '..' then
next
end
# makes sure the current iteration is not a sub directory
if not File.directory?(file) then
extension = File.extname(file)
fileName = File.basename(file, extension)
end
# strips off the last string if it contains a period
if fileName[fileName.length - 1] == "." then
fileName = fileName[0..-1]
end
# this is where I got stuck
reverse_markdown File.join(inDir, fileName, '.html') > File.join(outDir, fileName, '.md')
這是一個關於迭代和循環的問題。你有沒有看看Ruby'Dir'和'File'可以爲你做些什麼?最好的答案將考慮你的文件的結構,以及任何可能的限制你的寶石(請命名)。把你的問題放在第一個嘗試,我們很好去! –