Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to find all files in a directory - code must run both as RTC-Client and NAS

Posted on by 269

Hi

I want to find all files in a directory given a specific prefix and extension. I cannot find how to do this in Codeunit 419 "File mangement" Version NAV2013.

There is some code-example at Mibuso using DotNet (se below) - but this code works well running at Client but does not work running at a NAS.

Do you have another example ?

Thank you in advance.

Best regards

odri

 

 

Example

Obj := Folder.GetFiles('C:\Temp','*.txt');
Lst := Lst.List;
Lst.AddRange(Obj);
MESSAGE('%1',Lst.Count);
FOR i := 0 TO Lst.Count - 1 DO BEGIN   MESSAGE(FORMAT(Lst.Item(i))); END;

Folder   DotNet   System.IO.Directory.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'    Lst   DotNet   System.Collections.Generic.List`1.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'    Obj   DotNet   System.Object.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'   

 

 

 

 

 

*This post is locked for comments

  • odri Profile Picture
    odri 269 on at
    RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    Hi

    Thank's I find the System.IO - but got Message : ...

    ".....Could not find a part of the path 'S:\Sapalogic\XMLData\' "

    I try both 2.0.0.0 and 4.0.0.0 (x64)

     

    I can  use another code from mibuso - Folder.GetFiles - see code below - it Works - but this code is not allowed to run in job-Queue at NAS.

      error message "translated" : "....Client revocation call  is not supported at Microsoft Dynamics NAV Server"                                        

     

    ------------

    I got error message with this code

    MyPath := 'S:\Sapalogic\XMLData\';

    DirectoryInfo := DirectoryInfo.DirectoryInfo(MyPath);

    List := DirectoryInfo.GetFiles('*.xml'); // ('*.xml');

    enumerator := List.GetEnumerator();

    // Once we have a list of enumerator class then we can loop through each object

    WHILE enumerator.MoveNext DO BEGIN

     FileInfo:= enumerator.Current();

     CLEAR(FileCopy);

     FileCopy.Name := FileInfo.Name;

     FileCopy.Ref  := 'ENUMERATOR';

     FileCopy.INSERT(TRUE);

    END;

    {

    This code works

    MyPath := 'S:\Sapalogic\XMLData\';

    Prefix := 'ITEM';

    Obj := Folder.GetFiles(MyPath,Prefix  + '*.xml');

    Lst := Lst.List;

    Lst.AddRange(Obj);

    IF Lst.Count > 0 THEN BEGIN

      FOR NumFiles := 0 TO Lst.Count - 1 DO BEGIN

         CLEAR(FileCopy);

         // MESSAGE(FORMAT(Lst.Item(NumFiles)));

         FileCopy.Name := FORMAT(Lst.Item(NumFiles));

         FileCopy.Ref  := 'Folder.GetFiles';

         FileCopy.INSERT(TRUE);

      END

    END;

    }

  • Carlos Herrando Profile Picture
    Carlos Herrando 165 on at
    RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    Hi again,

    I found the solution, instead of select System.IO you have to select 'mscorlib' when selecting the assembly, then you can select each one of the System.IO or System.Collections types.

    Best regards,

         Carlos

  • Carlos Herrando Profile Picture
    Carlos Herrando 165 on at
    RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    Same problem here Oddvar, did you find any solution?

    Regards

         Carlos

  • odri Profile Picture
    odri 269 on at
    RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    Hi

    Thank you -

    but I cannot find any System.IO with token PublicKeyToken=b77a5c561934e089 at my PC with Windows 8.0 and NAV213 FP1

    The only System.IO have PublicToken=b03f5f7f11d50a3a - but this is "empty" - there are no Type ("Methods") to select.

    I have "search" in other DotNet Subtype but cannot find any with ".....IO.Directory"

    Do you have some ideas ?

    Best regards

    Oddvar

     

  • Rashed Profile Picture
    Rashed 3,765 on at
    RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    here is an example.

    mibuso.com/.../using-enumerators-in-cal-to-iterate-through-files-in-a-folder

  • odri Profile Picture
    odri 269 on at
    RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    We are running NAV2013 FP1.

    In earlier classic version we use the File-table functionality. This is not able to use at RTC – and I cannot find similar code to support this case in NAV2013.

     

    Task :

    How to find all files at a given direcotory – in this example P:\xml\in\

     

    I have to read all xml-files at directory P:\xml\in\

    • step 1 : the files are moved to P:\xml\error\
    • step 2 : the files are moved to P:\xml\read\ when read is completed.

    To move files I use codeunit 419 File Management.

     

    I find some code at Mibuso which use DotNet (se first mail) – this works well run at RTC-client but not at NAS-jobque.

     

    When the job is  Set Status to Ready I get this message in jobqeue:

     

                           

     

    Translated : “Client revocation is not supported at NAV Server.”

     

    Can you give me some advice where I can find code example for this case.

  • RE: How to find all files in a directory - code must run both as RTC-Client and NAS

    What exactly do you mean when saying "does not work" running on NAS?

    Keep in mind that C:\Temp will be searched on the machine that is running the NAS service.

    Additionally, MESSAGEs do not work in NAS of the NAV 2013 RTM version. In order to be able to read them again in the WIndows event log, you will need to upgrade to build 34550 (KB2830230) or higher.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans