在 BC 19 中删除 DotNet

发布于 2025-01-17 15:24:26 字数 387 浏览 5 评论 0原文

我想摆脱 DotNet。

是否有任何代码单元可以用于此代码(也许是文件管理中的某些内容):

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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北渚 2025-01-24 15:24:26

您确实可以为此使用文件管理 codunit,但是它只能删除直接依赖性。 文件管理只是围绕相同dotnet组件的包装器。

在所有情况下,如果要使用文件系统,则需要在app.json中将target 设置为 onprem 。

以下代码应与您的示例相同:

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文