본문 바로가기
Flutter/Flutter FAQ

Flutter 플러터: 파일의 파일 이름 가져오기, Flutter: Get the filename of a File

by 베타코드 2023. 8. 16.
반응형

질문


이것은 꽤 간단할 것으로 생각했지만, 해결할 수 없는 것 같습니다. File file이 있고 그 안에는 file.path라는 경로가 있습니다. 이 경로는 /storage/emulated/0/Android/data/my_app/files/Pictures/ca04f332.png와 같은 것을 출력하지만, ca04f332.png만 얻을 수 있는 방법을 찾을 수 없습니다.


답변


다트 basename 함수를 사용할 수 있습니다. 이 함수는 path 라이브러리에서 제공됩니다:

import 'package:path/path.dart';

File file = new File("/dir1/dir2/file.ext");
String basename = basename(file.path);
# file.ext
반응형

댓글