renameDirectory function

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

Implementation

Future<void> renameDirectory(String oldPath, String newPath) async {
  try {
    final directory = Directory(oldPath);

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