how to rename or delete file in local storage using flutter

Viewed 78

I am developing an audio player using flutter.

In this project, I am using on_audio_query package to list all audio files from my mobile, then select one to play it.

I want to know, is there anyway to rename a file or delete it?

So the user can select one file and rename it, or select one or multiple files and delete them.

Thanks in advance

1 Answers

Try this example:

Future  changeFileNameOnly(File file, String newFileName) {
  var path = file.path;
  var lastSeparator = path.lastIndexOf(Platform.pathSeparator);
  var newPath = path.substring(0, lastSeparator + 1) + newFileName;
  return file.rename(newPath);
}
Related