I thought this would be pretty straight-forward, but can't seem to get this. I have a File file
and it has a path file.path
which spits out something like /storage/emulated/0/Android/data/my_app/files/Pictures/ca04f332.png
but I can't seem to find anything to get just ca04f332.png
.
To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null. Syntax: public static string GetFileName (string path);
When using Flutter Official path_provider package, getExternalStorageDirectory() will always return path to /storage/emulated/0/your-package-name/files. The plugin ext_storage uses a deprecated version of the Android embedding.
You can use the basename
function from the dart path library:
import 'package:path/path.dart'; File file = new File("/dir1/dir2/file.ext"); String basename = basename(file.path); # file.ext
File file = new File("/storage/emulated/0/Android/data/my_app/files/Pictures/ca04f332.png"); String fileName = file.path.split('/').last; print(fileName);
output = ca04f332.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With