Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-io/src/utils/mkdir.rs
6939 views
1
use std::io;
2
3
use polars_utils::plpath::PlPathRef;
4
5
pub fn mkdir_recursive(addr: PlPathRef<'_>) -> io::Result<()> {
6
if let Some(path) = addr.as_local_path() {
7
std::fs::DirBuilder::new().recursive(true).create(
8
path.parent()
9
.ok_or(io::Error::other("path is not a file"))?,
10
)
11
} else {
12
Ok(())
13
}
14
}
15
16
#[cfg(feature = "tokio")]
17
pub async fn tokio_mkdir_recursive(addr: PlPathRef<'_>) -> io::Result<()> {
18
if let Some(path) = addr.as_local_path() {
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
} else {
27
Ok(())
28
}
29
}
30
31