checkFileExists function

File checkFileExists(
  1. String path, [
  2. String? name
])

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

Implementation

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

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

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

  return File(path);
}