Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

AX 2012 - X++ copy folders

Posted on by Microsoft Employee

Hi all,

I have a 'master_folder' folder. In this folder has 8 sub-folders.

My question: How to use the X++ to copy these sub-folders from 'master_folder' to another folder?

Thanks.

*This post is locked for comments

  • Hariharans87 Profile Picture
    Hariharans87 4,971 on at
    RE: AX 2012 - X++ copy folders

    Please mark the reply as verified and close.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX 2012 - X++ copy folders

    Thanks. It works.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX 2012 - X++ copy folders

    Hi Anil,

    WinAPI no copy folders, it has copy file.

  • Johnkrish Profile Picture
    Johnkrish 781 on at
    RE: AX 2012 - X++ copy folders

    Hi Simon,

        Just try this code. it will give you the folder name with sub folders. and then use WINAPI for copying the same.

    static void Johnkrish_FolderFind(Args _args)
    {
    int k; // counter for result loop
    container dirs; // container for result
    filePath path = @"E:\JohnkrishFolder"; // 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("Completed");


    }

  • Suggested answer
    Hariharans87 Profile Picture
    Hariharans87 4,971 on at
    RE: AX 2012 - X++ copy folders

    Please refer this link dynamicsaxhari.blogspot.in/.../copy-sub-folder-and-files-by-using-x.html

    It may help you.

  • anil1268 Profile Picture
    anil1268 222 on at
    RE: AX 2012 - X++ copy folders

    hello Simon,

    Just check the WinAPI class in x++, you may find the relevant methods to perform this operation.

  • Suggested answer
    Pir_Rana Profile Picture
    Pir_Rana 836 on at
    RE: AX 2012 - X++ copy folders

    Hi,

    As far I know, you need to create sub-folder structure into another folder (into destination folder) and then copy the sub-folder files accordingly.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans