getFileExtension static method

String getFileExtension(
  1. String? path, {
  2. bool withDot = true,
})

get file extension

Implementation

static String getFileExtension(String? path, {bool withDot = true}) {
  String extension = "";
  if (withDot) {
    if (!Files._isNullOREmpty(path)) {
      if (path.toString().contains(".")) {
        extension = path.toString().substring(
          path.toString().lastIndexOf("."),
        );
      } else {
        extension = ".${path.toString()}";
      }
    }
  } else {
    if (!Files._isNullOREmpty(path)) {
      if (path.toString().contains(".")) {
        extension = (path.toString().substring(
          path.toString().lastIndexOf("."),
        )).replaceAll(".", "");
      } else {
        extension = path.toString();
      }
    }
  }
  return extension;
}