rename static method

Future<File> rename(
  1. String filePath,
  2. String newName, {
  3. bool keepExtension = true,
})

Implementation

static Future<File> rename(
  String filePath,
  String newName, {
  bool keepExtension = true,
}) async {
  File sourceFile = File(filePath);
  String fileExtension = path_operations.extension(filePath);

  String parentPath = sourceFile.parent.path.strip('/');

  String newPath;
  if (keepExtension) {
    newPath = '$parentPath/$newName$fileExtension';
  } else {
    newPath = '$parentPath/$newName';
  }
  return sourceFile.rename(newPath);
}