checkDirectoryExists function

Directory checkDirectoryExists(
  1. String path, [
  2. String? name
])

Check if the Directory at path exists, if not throw an ArgumentError.

Implementation

Directory checkDirectoryExists(
  String path, [
  String? name,
]) {
  final type = FileSystemEntity.typeSync(path);

  if (FileSystemEntityType.notFound == type) {
    throw ArgumentError.value(
      path,
      name,
      "The directory does not exist",
    );
  }

  if (FileSystemEntityType.directory != type) {
    throw ArgumentError.value(
      path,
      name,
      "The provided path does not lead to a directory, but to a $type",
    );
  }

  return Directory(path);
}