Flutter skip a directory from the copy file command - flutter

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.

Related

Flutter retrieving files from external storage

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.

flutter: how to create/write a file to a specific directory path

i'm trying to create/write a file to a specific directory. i already have my code but the problem is i always got an error saying:
flutter: FileSystemException: Cannot open file, path = '/var/mobile/Containers/Data/Application/AF14244D-E8C4-4B9A-8005-D7CA7CC3520B/Documents/cache/files/abcb-1234567890' (OS Error: No such file or directory, errno = 2)
here's my code:
Directory directory = Platform.isAndroid ? await getExternalStorageDirectory() : await getApplicationDocumentsDirectory();
String path = directory.path + '/cache/files';
File file = new File('$path/$fileID');
final results = await post(...);
file.writeAsBytesSync(results);
what am i missing?
additional question: if anyone would know how can i access created date of the file that i have just created? - reason for this is to delete them after a set date or like an expiry date.
appreciate any help. thank you in advance. =)
Are you sure this path exists?
I belive your code is executing part getApplicationDocumentsDirectory()
That mean you are not on android.
Can you access this path using other app (some file explorer etc)?
The interesting part is here:
'/cache/files' maybe this folder doesn't exist.
Here is on my Windows:
var dir = io.Directory.fromUri(Uri.directory('UNO\\DUE\\'));
dir.createSync(recursive: true);
var file = io.File('${dir.absolute.path}\demo.txt');
file.writeAsStringSync('ABCDEFHJ');
Without dir.createSync(recursive: true); without recursive parameter I have exactly same problem.

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"

Why does File.mkdirs() create two directories instead of one?

This code should create a single directory:
File[] dirs = context.getExternalFilesDirs(type);
File dir = new File(dirs[dirs.length-1].getAbsolutePath());
dir.mkdirs();
return dir;
When I run it, it creates two directories:
mnt/sdcard/Android/data/com.test.sdcard
storage/0D68-5DA2/Android/data/com.test.sdcard
Why are both of these created?
It is important that I only have 1 directory.

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.