Search This Blog

Thursday, December 4, 2014

Get Multiple files from Folder

static container Krishh_findMatchingFiles(str _folderPath,   str _filePattern   = '*.*')
    System.IO.DirectoryInfo     directory;
    System.IO.FileInfo[]        files;
    System.IO.FileInfo          file;
    InteropPermission           permission;

    str         fileName;
    counter     filesCount;
    counter     loop;
    container   mathchingFiles;

    permission  = new InteropPermission(InteropKind::ClrInterop);

    directory   = new System.IO.DirectoryInfo(_folderPath);
    files       = directory.GetFiles(_filePattern);
    filesCount  = files.get_Length();

    for (loop = 0; loop < filesCount; loop++)
        file            = files.GetValue(loop);
        fileName        = file.get_FullName();
        mathchingFiles  = conins(mathchingFiles, conlen(mathchingFiles) + 1, fileName);


    return mathchingFiles;

I placed the above method in Global class, so we can use that in your classes.
Make sure your folder should have access permissions when you are running in the batch.

static void Krishh_fetchFiles(Args _args)
    container   files;
    counter     loop;
    str         fileName;
   //Assign the folder path with the file pattern if you want to filter by ex *.txt or k*.txt or m*.*..etc.
    files = Global::Krishh_findMatchingFiles(AxdDocumentParameters::find().PaymJournalFile);

    for (loop = 1; loop <= conlen(files); loop++)
        fileName = conpeek(files, loop);


1 comment:

  1. Hi sir,

    I am facing problem while uploading excel of Budget transaction line .
    I am not able to upload dimension value to the AX.
    Thanks in Advance


Thanks for visiting my blog,
I will reply for your comment within 48 hours.