9

In my Flutter project for Windows, I want to run some .exe files that I want to embed in my project, instead of copying/pasting them by hand in the correct location.

So I tried to add the .exe files in my assets folder, like the following:

assets
  \exe
  \images

and add the exe folder in my pubspec.yaml file like the following:

flutter:
  assets:
    - assets/images/
    - assets/exe/

The good news is: the exe files are copied in the correct location when I build my project. The bad news is: I don't know how to get the absolute path of my exe folder in Dart.

So, is there a way to get the absolute path of the exe folder for a Windows project, or is there another way to embed my .exe files so I can get their paths and run them (using Process.start())?

Thanks.

matteoh
  • 2,810
  • 2
  • 29
  • 54

1 Answers1

4

Here is what I did to get the absolute path of the exe folder (only tested on Windows) :

// returns the abolute path of the executable file of your app:
String mainPath = Platform.resolvedExecutable;

// remove from that path the name of the executable file of your app:
mainPath = mainPath.substring(0, mainPath.lastIndexOf("\\"));

// concat the path with '\data\flutter_assets\assets\exe', where 'exe' is the
// directory where are the executable files you want to run from your app:
Directory directoryExe = Directory("$mainPath\\data\\flutter_assets\\assets\\exe")
matteoh
  • 2,810
  • 2
  • 29
  • 54