Friday, October 24, 2014

Fetching file name from the file path using X++

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 filepath as the parameter.It splits the filepath into three different strings filepath, filename and fileextension respectively.The usage of the function can be seen below.


    str    filepath; 
    str    filename; 
    str    fileType; 
    str    fileNameString;

    filepath = @'C:\Users\imran\AppData\Local\Text Document.txt';
    
    info(strFmt('File path  : %1', filepath));
    [filepath, filename, fileType] = fileNameSplit(filepath); 
    
    fileNameString= filename + fileType; 
    
    info(strFmt('File name : %1', filename));
    info(strFmt('File name with extension : %1', fileNameString));

Results:

   

2 comments:

  1. Hi Afnan,

    I just wondering how to specify/define the path if the file stored in the different IP/Computer.
    i have try to write the path like this :

    fileName = "\\[IP address]\\[Shared folder]\\testing.xlsx)";

    but the system cannot read my path.
    do you have information/solution for try to read/write a file that stored in the different IP address/Computer?

    Thanks for you attention.

    Husna

    ReplyDelete
  2. btw i am using
    SysExcelWorkBook xlsWorkBook;
    ;

    xlsWorkbook.SaveAs(filename);

    ReplyDelete