Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #212 Check if folder exists

Set the boolean b to true if path exists on the filesystem and is a directory; false otherwise.

#include <filesystem>
auto b = std::filesystem::is_directory(path);
with Ada.Directories;
use Ada.Directories;
B : constant Boolean :=
    Exists (Path) and then Kind (Path) = Directory;
System.IO;
bool b = Directory.Exists(path);
import 'dart:io';
var b = await Directory(path).exists();
import "os"
info, err := os.Stat(path)
b := !os.IsNotExist(err) && info.IsDir()
import java.io.File;
File f = new File(path);
boolean b = f.exists() && f.isDirectory();
$b = is_dir($path);
uses sysutils;
b := DirectoryExists(path);
use 5.010;
my $b = -e -d $path;
import os
b = os.path.isdir(path)
b = Dir.exist?( path )
use std::path::Path;
let b: bool = Path::new(path).is_dir();

New implementation...
< >
programming-idioms.org