use std::path::{Path, PathBuf};
use anyhow::{anyhow, Result};
use tokio::fs::canonicalize;
pub async fn output_pathname<P: AsRef<Path>>(i: P, ext: &str) -> Result<PathBuf> {
let mut copies = 0;
let mut output = canonicalize(i)
.await
.map_err(|err| anyhow!("Failed to canonicalize. {}", err))?;
while output.exists() {
copies += 1;
output.set_file_name(format!("{} ({})", output.to_string_lossy(), copies));
}
output.set_extension(ext);
Ok(output)
}