Convert Files Into A New Format While Copying Them Into A Duplicate Directory Structure In Rust

This is the code I'm using when I need to make new versions of files in a different format. It does the following:

  • Finds all `.txt` files via a glob search in an input directory

  • Creates a tuple with the input path plus an output file path in a new root directory and with a new file extension

  • Creates the directory structure under the output directory root

  • Returns a Vec of the tuples with the file paths for processing

use anyhow::Error;
use glob::glob;
use std::fs;
use std::path::PathBuf;

fn main() {
    let input_root = "test_input_dir";
    let input_extension = "txt";
    let output_root = "test_output_dir";
    let output_extension = "neo";
    let file_list =
        prep_structure(input_root, input_extension, output_root, output_extension).unwrap();

fn prep_structure(
    in_root: &str,
    in_ext: &str,
    out_root: &str,
    out_ext: &str,
) -> Result<Vec<(PathBuf, PathBuf)>, Error> {
    let mut response: Vec<(PathBuf, PathBuf)> = vec![];
    let mut glob_expression = String::from(in_root);
    for entry in glob(glob_expression.as_str())? {
        let in_path = entry?;
        let mut out_path = PathBuf::from(out_root);
        let check_dir = &out_path.parent().unwrap();
        if !check_dir.try_exists().unwrap() {
        response.push((in_path, out_path));