JamesZhang пре 1 година
родитељ
комит
a0b979f282
1 измењених фајлова са 25 додато и 2 уклоњено
  1. 25 2
      lib/util/fileUtils.dart

+ 25 - 2
lib/util/fileUtils.dart

@@ -57,13 +57,36 @@ Future<String> getFileMd5(String filePath) async {
   return hex.encode(digest.bytes);
 }
 
+Future<File?> createFile(String filePath) async {
+  try {
+    if (!await isFileExists(filePath)) {
+      File file = await File(filePath).create(recursive: true);
+      return file;
+    } else {
+      return File(filePath);
+    }
+  } catch (error) {
+    return null;
+  }
+}
+
+bool deleteFile(String filePath) {
+  try {
+    final file = File(filePath);
+    file.deleteSync();
+    return true;
+  } catch (error) {
+    return false;
+  }
+}
+
 
 createFolder(String folderPath) async {
   // 创建文件夹
   final Directory folder = Directory(folderPath);
   // 如果文件夹不存在,则创建
   if (!await folder.exists()) {
-    await folder.create();
+    await folder.create(recursive: true);
   } else {
     Log.d("Folder already exists");
   }
@@ -74,7 +97,7 @@ copyDirectory(Directory source, Directory destination) async {
     if (entity is Directory) {
       var newDirectory = Directory(
           path.join(destination.absolute.path, path.basename(entity.path)));
-      await newDirectory.create();
+      await newDirectory.create(recursive: true);
       await copyDirectory(entity.absolute, newDirectory);
     } else if (entity is File) {
       await entity.copy(