web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Natalie Karolak - the BC Docs Librarian Profile Picture
    1,955 on at

    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.

  • odri Profile Picture
    269 on at

    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.

  • Rashed Profile Picture
    3,765 on at

    here is an example.

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

  • odri Profile Picture
    269 on at

    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

     

  • Carlos Herrando Profile Picture
    171 on at

    Same problem here Oddvar, did you find any solution?

    Regards

         Carlos

  • Carlos Herrando Profile Picture
    171 on at

    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

  • odri Profile Picture
    269 on at

    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;

    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans