mobdr/lib/service/directories.dart

50 lines
1.7 KiB
Dart

import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:mobdr/service/shared_prefs.dart';
class directories {
Future<void> initDirectories() async {
// Get the application's document directory
final Directory documentsDir = await getApplicationDocumentsDirectory();
// Directory object for the "photos" directory in the documents directory
final Directory photosDir = Directory('${documentsDir.path}/photos');
// Directory object for the "cache" directory in the documents directory
final Directory cacheDir = await getTemporaryDirectory();
// Check if the "photos" directory exists
if (await photosDir.exists()) {
print(
'The "photos" directory already exists in the documents directory.');
} else {
// Create the "photos" directory if it does not exist
await photosDir.create();
print(
'The "photos" directory has been created in the documents directory.');
}
// save directories into shared Prefs
SharedPrefs().documentsDir = documentsDir.path;
SharedPrefs().photosDir = photosDir.path;
SharedPrefs().cacheDir = cacheDir.path;
// Get a list of all files in the "photos" directory
List<FileSystemEntity> files = await photosDir.list().toList();
// Print out the names of the files in the directory
for (FileSystemEntity file in files) {
print('File name in photo directory : ${file.path.split('/').last}');
}
// Get a list of all files in the "photos" directory
files = await cacheDir.list().toList();
// Print out the names of the files in the directory
for (FileSystemEntity file in files) {
print('File name in cache directory : ${file.path.split('/').last}');
}
}
}