'remove DotNet in BC 19
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;
Solution 1:[1]
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kaspermoerch |
