1

I'm trying to get list of files from a directory in D365 Business central , because in the AL language DotNet var is not supported, so i don't know how can i get those files paths.

In my requirement i know the path of folder but need to get actual files paths in that folder.

Ex: Folder is E:\Dynamically\

But i want to get files path like:

  1. E:\Dynamically\1.txt

  2. E:\Dynamically\2.txt

  3. E:\Dynamically\3.txt

I tried to search inbuilt function in Codeunit 419("File Management"), and tried to get using Azure function. I am adding my code for get file from that directory but it is for one file.

action("Import Files")
            {
                ApplicationArea = All;
                Image = Import;

                trigger OnAction();
                var
                    FromFile: Text;
                    FileMgt: Codeunit "File Management";
                begin
                    Init();
                    Message(FileMgt.GetExtension('E:\Dynamically\' + 
                    Format(GetFileName)));
                    FromFile := 'E:\Dynamically\' + Format(GetFileName);
                    "Attached File".Import(FromFile);
                    "Attched File Name" := Format(GetFileName);
                    "Attached file Extension" := 
                     FileMgt.GetExtension(Format(GetFileName));
                    Insert(true);
                    MESSAGE('Successfully Import.');
                end;
            }

Here's the result of my import File code.

enter image description here

bummi
  • 27,123
  • 14
  • 62
  • 101
Nav Dev
  • 11
  • 1
  • 6

1 Answers1

1

I would suggest that you use GetClientDirectoryFilesList or GetServerDirectoryFilesList in Codeunit 419 they both take NameValueBuffer (Table 813) and DirectoryPath (text) as arguments. You could then use NameValueBuffer to get all files.

These functions are probably only available for on-premise so you would have to target your extension to internal in app.json.

theschitz
  • 385
  • 1
  • 6
  • 18