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 Microsoft Employee

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

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    Tharanga Chandrasekara 23,116 on at
    RE: how to delete all files in folder at a time?

    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.

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    Tharanga Chandrasekara 23,116 on at
    RE: how to delete all files in folder at a time?

    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

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,614 on at
    RE: how to delete all files in folder at a time?

    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
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to delete all files in folder at a time?

    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
    keoma Profile Picture
    keoma 32,675 on at
    RE: how to delete all files in folder at a time?

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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans