Skip to main content

polars_io/utils/
mkdir.rs

1use std::io;
2
3use polars_utils::pl_path::PlRefPath;
4
5pub fn mkdir_recursive(path: &PlRefPath) -> io::Result<()> {
6    if !path.has_scheme() {
7        std::fs::DirBuilder::new().recursive(true).create(
8            path.parent()
9                .ok_or(io::Error::other("path is not a file"))?,
10        )?;
11    }
12
13    Ok(())
14}
15
16#[cfg(feature = "tokio")]
17pub async fn tokio_mkdir_recursive(path: &PlRefPath) -> io::Result<()> {
18    if !path.has_scheme() {
19        tokio::fs::DirBuilder::new()
20            .recursive(true)
21            .create(
22                path.parent()
23                    .ok_or(io::Error::other("path is not a file"))?,
24            )
25            .await?;
26    }
27
28    Ok(())
29}