I tried the following but I don't think it's particularly pretty:
let path = "target/dir"; if !std::path::Path::new(&path).exists() { std::fs::create_dir(path)?; }
You can use os. path. exists('<folder_path>') to check folder exists or not.
To create a directory if not exist in Python, check if it already exists using the os. path. exists() method, and then you can create it using the os. makedirs() method.
$Folder = 'C:\Windows' "Test to see if folder [$Folder] exists" if (Test-Path -Path $Folder) { "Path exists!" } else { "Path doesn't exist." } This is similar to the -d $filepath operator for IF statements in Bash. True is returned if $filepath exists, otherwise False is returned.
std::fs::create_dir_all
:
Recursively create a directory and all of its parent components if they are missing.
Examples
use std::fs; fs::create_dir_all("/some/dir")?;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With