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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

how to delete all files in folder at a time?

(0) ShareShare
ReportReport
Posted on by

Hi 

i have an issue to delete all files in a folder through nav. is this possible Then how?

i did on R & d for this i found ERASE function it works for to delete one file not all files

i written code as like see below

If FilenameG<> '' Then

 Erase(FilenameG);

Here FilenameG is Text Varible and it is having my Files Folder like

FilenameG:='C:\Users\Mail\'; 

when use ERASE it's not work to me.

Any Suggestions........

Regards,

Ramesh.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    load file list using .net (Directory.GetFiles), iterate through list, delete each file in loop.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi ramesh,

    Maybe next code will help you ;

    Variables

    DNObj DotNet System.Object.'mscorlib

    DNFolder DotNet System.IO.Directory.'mscorlib

    DNLst DotNet System.Collections.Generic.List`1.'mscorlib

    DNFile DotNet System.IO.File.'mscorlib

    DNPath DotNet System.IO.Path.'mscorlib

    i Integer

    Code

    DNObj := DNFolder.GetFiles('Source folder','*.yourextension');

    DNLst := DNLst.List;

    DNLst.AddRange(DNObj);

    FOR i := 0 TO DNLst.Count - 1 DO BEGIN

     //IN THIS CASE I MOVE THE FILES BUT YOU CAN DELETE

     DNFile.Move(DNLst.Item(i),'Destination      folder'+'\'+DNPath.GetFileName(DNLst.Item(i)));

    END;

    Best Regards,

    Carlos.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 on at

    You have to do something like this where RecFile is of type Record 2000000022

                     recFile.RESET;

                     recFile.SETRANGE(Path,FolderPath);

                     recFile.SETRANGE("Is a file",TRUE);

                     IF recFile.FINDSET THEN

                       REPEAT

                             FILE.ERASE(FolderPath + recFile.Name);

                       UNTIL recFile.NEXT = 0;

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    You need to go through each file and then delete it or else you need to use .net variable to do it for you.

    Check this one : www.csharp-examples.net/delete-all-files

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    You can create a DLL with the code in that previous article and then add it to Dynamics NAV. Then call the DLL and pass the folder path. This will sort your problem.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
TAHER_El_Mehdi Profile Picture

TAHER_El_Mehdi 2

#1
sliderxb Profile Picture

sliderxb 2

#1
broberts Profile Picture

broberts 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans