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 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,243 Super User 2025 Season 2 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

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