file_util.dart 573 B

12345678910111213141516171819202122232425
  1. import 'dart:io';
  2. import 'package:path/path.dart' as path;
  3. /// 文件工具类
  4. class FileUtil {
  5. /// 文件是否存在
  6. static bool fileExists(File file) {
  7. return file.existsSync();
  8. }
  9. /// 获取文件的绝对路径
  10. static String getFilePath(File file) {
  11. return file.path;
  12. }
  13. /// 获取文件名(带扩展名)
  14. static String getFileName(File file) {
  15. return path.basename(file.path);
  16. }
  17. /// 获取文件名(不带扩展名)
  18. static String getFileNameWithoutExt(File file) {
  19. return path.basenameWithoutExtension(file.path);
  20. }
  21. }