diff --git a/src/cli/output.rs b/src/cli/output.rs index 5ba60f3..1e89378 100644 --- a/src/cli/output.rs +++ b/src/cli/output.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::fs::{create_dir_all, File}; use std::path::Path; use rand::Rng; use crate::cli::cli::OutputFormat; @@ -13,6 +13,14 @@ pub fn write, W: Walker

, Sp: Spawner

, S format: OutputFormat, output: &Path, ) { + // If the parent does not exist (and we are not in the root or operating a relative 1-component-length path)) + // create it. This greatly simplifies the harness code. + if let Some(parent) = output.parent() && + parent.to_str().map(|x| x != "").unwrap_or(true) && + !parent.exists() { + create_dir_all(parent).expect("Failed to create path to output"); + } + match format { OutputFormat::FullDataJson => write_json_full_data(sys, output), OutputFormat::Positions => write_csv_positions(sys, output),