Skip to content

Commit c62956d

Browse files
committed
create dir to output file if not exists
1 parent 9332d1b commit c62956d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use rayon::{
1111
};
1212
use request::{Client, Response};
1313
use std::{
14-
fs::File,
14+
fs::{self, File},
1515
io::{Read, Write},
1616
num::{NonZeroU32, NonZeroUsize},
17+
os,
1718
path::Path,
1819
thread,
1920
time::Duration,
@@ -125,9 +126,15 @@ fn read_body_from_file(file_path: &str) -> Result<Vec<u8>> {
125126

126127
fn write_to_csv(path: &str, res: &[Response]) -> Result<()> {
127128
let pth = Path::new(&path);
129+
128130
let mut f = if pth.exists() {
129131
File::options().append(true).open(pth)
130132
} else {
133+
if let Some(parent) = pth.parent() {
134+
if !parent.exists() {
135+
fs::create_dir_all(parent)?;
136+
}
137+
}
131138
File::create(pth)
132139
}?;
133140

0 commit comments

Comments
 (0)