Skip to content

Commit

Permalink
Create parent directories if neccessary
Browse files Browse the repository at this point in the history
  • Loading branch information
kremso committed Jan 28, 2013
1 parent 8c5578c commit 534fe55
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/docpipe/filters/extract_images.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'docpipe/commands/ghostscript'
require 'docpipe/base_name'
require 'fileutils'

module Docpipe
class ExtractImages
Expand All @@ -14,6 +15,7 @@ def initialize(next_filter, inner_pipeline, options = {})

def call(env)
output_path = File.join(env[:output_path], @output_lambda.call(BaseName.filename(env[:document_path])))
FileUtils.mkdir_p(File.dirname(output_path)) unless File.exist?(File.dirname(output_path))
pages = @pdf_to_images.convert(env[:document_path], output_path, @format, @dpi)
pages.each do |page_number, page_path|
@inner_pipeline.run(env.merge(document_path: page_path, page_number: page_number, parent_document_path: env[:document_path]))
Expand Down
1 change: 1 addition & 0 deletions lib/docpipe/filters/extract_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(next_filter, inner_pipeline, options)

def call(env)
output_path = File.join(env[:output_path], @output_lambda.call(BaseName.filename(env[:document_path]) + ".txt"))
FileUtils.mkdir_p(File.dirname(output_path)) unless File.exist?(File.dirname(output_path))
unless @dte.extract(env[:page_number], env[:parent_document_path], output_path)
@ocr.extract(env[:document_path], output_path, @language)
end
Expand Down

0 comments on commit 534fe55

Please sign in to comment.