renameFile function

Future<void> renameFile(
  1. String oldPath,
  2. String newPath
)

Implementation

Future<void> renameFile(String oldPath, String newPath) async {
  try {
    final file = File(oldPath);

    // Check if the file exists
    if (await file.exists()) {
      // Rename (move) the file
      await file.rename(newPath);
      print('File $oldPath renamed $newPath successfully.');
    } else {
      print('File $oldPath does not exist.');
    }
  } catch (e) {
    print('Error renaming file: $e');
  }
}