Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to get the File from the particular path

Posted on by Microsoft Employee

Hi All,

I am trying to pick only the filename from the specified path but not able to do that.

Previously i was comparing the filename with the filename that exists in the Folder.

If it was there then i was importing the data to NAV.

But now if in that filepath i have 10 files that starts with "CC" then one by one i have to import all the files.

Below is my code.Please suggest.

Thank u in advance.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get the File from the particular path

    //START-004

    DSVFileName:='CC'+CONVERTSTR(FORMAT(TODAY,0,'<day,2><month,2><year4>'),' ','0')+'.txt';

    IF EXISTS(CustClrSetup.Filepath+DSVFileName) THEN

     CustClrSetup."BAT Text File":= CustClrSetup.Filepath+DSVFileName;

    //STOP-004

    FileName := CustClrSetup."BAT Text File";

    WHILE STRPOS(FileName,'\') > 0 DO

     FileName := COPYSTR(FileName,STRPOS(FileName,'\') + 1);

    PathName := CustClrSetup.Filepath;

    NewFileName:= 'CC'+CONVERTSTR(FORMAT(TODAY,0,'<day,2><month,2><year4>') ,' ','0')+'.txt';

    IF CustClrSetup."BAT Text File" <> PathName  + FileName THEN

     ERROR(Text50000);

    FTPFile.WRITEMODE(TRUE);

    FTPFile.TEXTMODE(TRUE);

    FTPFile.CREATE(PathName + CustClrSetup."FTP File Name");

    FTPFile.WRITE(CustClrSetup."User Name");

    FTPFile.WRITE(CustClrSetup.Password);

    FTPFile.WRITE('lcd C:\');

    FTPFile.WRITE('cd order_sys');

    FTPFile.WRITE('hash');

    FTPFile.WRITE('get ' + FileName);

    FTPFile.WRITE('bye');

    FTPFile.CLOSE;

    BATFile.WRITEMODE(TRUE);

    BATFile.TEXTMODE(TRUE);

    BATFile.CREATE(PathName + CustClrSetup."BAT File Name");

    BATFile.WRITE('C:');

    BATFile.WRITE('FTP -s:' + PathName + CustClrSetup."FTP File Name" + CustClrSetup."Server Address");

    BATFile.CLOSE;

    ReturnCode := SHELL(PathName + CustClrSetup."BAT File Name");

    ERASE(PathName + CustClrSetup."FTP File Name");

    ERASE(PathName + CustClrSetup."BAT File Name");

    }

    IF EXISTS(PathName+FileName) THEN BEGIN

     COPY(PathName+FileName,CustClrSetup."Backup Filepath"+NewFileName);

     ERASE(PathName+FileName);

    END ELSE

     ERROR('Cannot find %1',PathName+FileName);

    ImportFile.TEXTMODE(TRUE);

    ImportFile.OPEN(CustClrSetup."Backup Filepath"+NewFileName);

  • Suggested answer
    Maneesha Profile Picture
    Maneesha 5,889 on at
    RE: How to get the File from the particular path

    Pushpa ,

    your code image/text are missing can you repost it ?

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: How to get the File from the particular path

    Your code is not visible .Kindly paste the code again

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans