Get the filename from the File Path using X++ in AX 2012

Description:-

AX has a standard method in the Global Class to split the file name from the entire file path.The method is fileNameSplit().The method takes file path as the parameter.It splits the file path into three different strings file path, file name, file extension respectively.The usage of the function can be seen below.

Create Job from AOT:-
  • In the AOT, click Job.
  • Right-click the Job node, and then select New Job.

static void Filename(Args _args)
{
    Filename filepath;
    Filename filename;
    Filename fileType;
    str fileNameString,fileNamePath;
    ;
    fileNamePath=@"C:\Users\umesh.adroja\Desktop\DocumentsFile.docx";
    [filepath, filename, fileType] = fileNameSplit(fileNamePath);
    fileNameString= filename + fileType;
    info(strFmt("filename=%1 \nfileType=%2",filename,fileType));
}

Now the fileNameString will return you the file name with extension.

Related Posts

Previous
Next Post »

2 comments

comments
Anonymous
March 13, 2018 at 4:03:00 AM GMT+5:30 delete

I'm gone tto convey my little brother, that he should also visit this weblog on regular basis
to obtain updated from newest reports.

Reply
avatar
March 23, 2020 at 9:01:00 AM GMT+5:30 delete

Hi Umesh.,

i just wondering how to define/specify if the file in the different komputer/server?
i have try to write the path like this :
fileName = "\\[IP ADDRESS]\\[shared folder]\\testing.xlsx)";

but is not work.
do you have a solution for this?

thank u.

Reply
avatar

Thanks for comments.....