From 534fe5534f460ba7e422a37c1580c9de459ee852 Mon Sep 17 00:00:00 2001 From: Tomas Kramar Date: Mon, 28 Jan 2013 18:15:43 +0100 Subject: [PATCH] Create parent directories if neccessary --- lib/docpipe/filters/extract_images.rb | 2 ++ lib/docpipe/filters/extract_text.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/docpipe/filters/extract_images.rb b/lib/docpipe/filters/extract_images.rb index e642ad4..4aca89d 100644 --- a/lib/docpipe/filters/extract_images.rb +++ b/lib/docpipe/filters/extract_images.rb @@ -1,5 +1,6 @@ require 'docpipe/commands/ghostscript' require 'docpipe/base_name' +require 'fileutils' module Docpipe class ExtractImages @@ -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])) diff --git a/lib/docpipe/filters/extract_text.rb b/lib/docpipe/filters/extract_text.rb index 8cba567..d3370ca 100644 --- a/lib/docpipe/filters/extract_text.rb +++ b/lib/docpipe/filters/extract_text.rb @@ -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