replaceFileName static method

String replaceFileName({
  1. required String path,
  2. required String newFileName,
  3. required String pathSeparator,
})

converts /some/path/file.json to /some/path/newFile.json

Implementation

static String replaceFileName({
  required String path,
  required String newFileName,
  required String pathSeparator,
}) {
  final index = path.lastIndexOf(pathSeparator);
  if (index == -1) {
    return newFileName;
  } else {
    return path.substring(0, index + pathSeparator.length) + newFileName;
  }
}