Flutter retrieving files from external storage - flutter

Im trying to list all the mp3 files in the Downloads folder using
Directory dir = Directory('/storage/emulated/0/Download/');
List<FileSystemEntity> listOfAllFolderAndFiles = dir.listSync(recursive: true);
print(listOfAllFolderAndFiles);
but it only prints sub-folders and not any mp3 files.

Related

Flutter skip a directory from the copy file command

I'm copying files from one directory to another, but I want to exclude a directory, how can I proceed?
I tried to use the file_manager package as well but it doesn't work
var fm = FileManager(root: Directory('${externalDir.path}'));
var files = await fm.filesTree(
excludedPaths: ['/storage/emulated/0/Android/data/com.xxx.xxx/files/TEMP'],
extensions: ["mp3"],
);
in this way it should return me a list of mp3 files only, excluding the TEMP folder and its contents but this is not the case.

How to create folder which user able to see in Flutter?

I tried to create folder with path_provider package with this code.
final Directory directory = await getExternalStorageDirectory();
print("path1="+directory.path );// this is using path_provider
String directoryPath = directory.path + '/bozzetto_camera';
await Directory(directoryPath).create(recursive: true).then((value){
print("path="+value.toString());
});
And in console it shows path=Directory: '/storage/emulated/0/Android/data/com.example.water_delivery_app/files/bozzetto_camera'.
In file manager I could not find any folder.I tried this answer but it did not work I am using a real android device via usb. So how can create directory that user can see?

Batch Printing files to new folder as PDF's

I have a folder of 2000+ PDF files that I need to print and resave as new PDF files in a separate folder using the original file name. Is there a way to do this in powershell or using a CMD?
I have tried to select multiple files in the folder to print at the same time by right clicking and selecting the print option. However this gets stuck at the window requesting a new file name and a destination folder which I am unable to provide as each file needs to have the original file name.
// the directory to store the output.
string directory = Environment.GetFolderPath
(Environment.SpecialFolder.MyDocuments);
// initialize PrintDocument object
PrintDocument doc = new PrintDocument() {
PrinterSettings = new PrinterSettings() {
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = Path.Combine(directory, file + ".pdf"),
}
};
doc.Print();
I would like to see the new PDF file saved as a new PDF in the destination directory folder with the same file name as the origin directory.
Origin Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\NonRedacted --> Origin File name "Random_Name.PDF"
Destination Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\Redacted --> Destination File Name "Random_Name.PDF"

How to find absolute path fo the "assets" folder of the Flutter app?

Here is the setup in side of my
pubspec.yaml
...
path_provider: ^0.4.1
assets:
- assets/
- assets/a.txt
...
I try to find way to access to the "assets" directory to read content of the text file named "a.txt" where it should read in relative way as "assets/a.txt".
Here is my code in my
main.dart:
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
String fPath = '${appDocDir.parent.path}/assets/a.txt';
new File(fPath).readAsString().then((String contents) {
print("FILE:..... "+contents);
});
And here I got this error:
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
FileSystemException: Cannot open file, path = '/var/mobile/Containers/Data/Application/EE2A0E91-6543-4CE3-A82B-3B69BB892BFC/assets/a.txt' (OS Error: No such file or directory, errno = 2)
Seem like the ... EE2A0E91-6543-4CE3-A82B-3B69BB892BFC/ is not the root directory of the app to concat with my file assets/a.txt.
How can I find the exact absolute path of my a.txt file in order to read it using File() class?
You need to use AssetBundle to read assets.
For example https://docs.flutter.io/flutter/services/AssetBundle/load.html or https://docs.flutter.io/flutter/services/AssetBundle/loadString.html
See also https://flutter.io/docs/development/ui/assets-and-images#loading-text-assets

How can we read a config file stored at a location relative to the Mirth Connect Installation directory?

How can we read a config file stored at a location relative to the Mirth Connect Installation directory?
For example if Mirth is installed in /opt/Mirth-Connect directory and I want to read a file from /opt/Mirth-Connect/conf directory without specifying the fully qualified path name.
We are using multiple instances of Mirth for different environments which are installed on the same machine, So I can't hard code full path in channel configurations.
You can read a config file stored at a location relative to the Mirth Connect Installation directory basically in the same way as you would read any other file, i.e.:
var folder = new java.io.File("./conf");
var listOfFiles = folder.listFiles();
for (var i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
// Do what you need with the file - listOfFiles[i].getName());
}
}
The first line gives you a path relative to the mcserver.exe (in Windows env) installation.
Accordingly, folder = File(".") is a Mirth root folder.