Home > front end >  remove DotNet in BC 19
remove DotNet in BC 19

Time:04-01

I want to get rid of the DotNet.

Are there any Codeunits I can use for this code (Maybe something in the FileManagement):

procedure GetNoOfFilesInFolder(): Integer
var
    DirectoryInfo: DotNet DirectoryInfo;
    Directory: DotNet Directory;
begin
    IF NOT Directory.Exists(pathToFolder) THEN
        EXIT(-1);
    DirectoryInfo := DirectoryInfo.DirectoryInfo(pathToFolder);
    EXIT(DirectoryInfo.GetFiles().Length);
end;

CodePudding user response:

You can indeed use the File Management codeunit for that, however it only removes the direct DotNet dependency. File Management is just a wrapper around the very same DotNet assemblies.

Under all circumstances if you are to work with the file system you are required to set target to OnPrem in your app.json.

The following code should accomplish the same as your example:

local procedure GetNoOfFilesInFolder(PathToFolder: Text): Integer
var
    FileList: Record "Name/Value Buffer" temporary;
    FileManagement: Codeunit "File Management";
begin
    if not FileManagement.ServerDirectoryExists(PathToFolder) then
        exit(-1);

    FileManagement.GetServerDirectoryFilesList(FileList, PathToFolder);
    exit(FileList.Count);
end;
  • Related