Skip to main content

Get folders and subfolders

static void KlForLoopFoldersSystemIO(Args _args)
{
    int                 k;                  // counter for result loop
    container           dirs;               // container for result
    filePath            path = @"C:\temp";  // input path

    container getDirectories(str _dir, boolean _inclSubDirs = true)
    {
        container           dList;          // container to cast array into
        int                 i;              // counter for array loop
        System.Array        directories;    // array for result from .NET call
        #Define.Pattern("*")                // input pattern: * = all
        ;

        // assert interoppermissions for .NET interop
        new InteropPermission(InteropKind::ClrInterop).assert();

        // get directories using .NET interop
        if(_inclSubDirs)
        {
            // include subdirectories
            directories = System.IO.Directory::GetDirectories(_dir, #Pattern, System.IO.SearchOption::AllDirectories);
        }
        else
        {
            // only top directory
            directories = System.IO.Directory::GetDirectories(_dir, #Pattern, System.IO.SearchOption::TopDirectoryOnly);
        }

        // loog .NET array and put the values in a container for easier use in x++
        for( i=0;i<ClrInterop::getAnyTypeForObject(directories.get_Length()); i++ )
        {
            dList = conins(dList, conlen(dList)+1, ClrInterop::getAnyTypeForObject(directories.GetValue(i)));
        }

        // revert assertion to prevent multiple calls to the assert() method
        CodeAccessPermission::revertAssert();

        // return result container
        return dList;
    }
    ;

    // get directories
    dirs = getDirectories(path);

    // use optional parameter to disable sub directories
    // dirs = getDirectories(path, false);

    // print the result
    for(k=1;k<= conlen(dirs); k++)
    {
        // print the result to screen
        info(conpeek(dirs, k));
    }

    // we're done
    info("done");
}

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }