web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Creating a folder on fileSystem dynamics ax

(0) ShareShare
ReportReport
Posted on by 916

Hello ,

To check folder existence i use WinApi::pathExists, and to create folder in local path i use  WinApi::createDirectory or WinApi::createDirectoryPath:

static void createFileDirectory(Args _args)
{
    // str  path = 'C:\\Users\\Test\\Desktop\\CreateFolder\\aFolder';
    str      path = '\\Server001\\Users\\Test\\CreateFolder\\aFolder';
    ;
    if (!WinApi::pathExists(path))
    {
        WinApi::createDirectoryPath(path);
    }
    info('Done');
}

But using bellow path , i can't create folder in shared path :

str      path = '\\Server001\\Users\\Test\\CreateFolder\\aFolder';

How can i acheive this using X++.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Alex,

    You probably need to use  

    path = '\\\\Server001\\Users\\Test\\CreateFolder\\aFolder';

    or

    path = @'\\Server001\Users\Test\CreateFolder\aFolder';

    If it won't help you need to check if you have rights to create a folder.

  • Hariharans87 Profile Picture
    3 on at

    Try with System.IO.Directory::CreateDirectory(_path);

    Refer into this link community.dynamics.com/.../112352

  • Verified answer
    ALAhmed Profile Picture
    916 on at

    Thank you for the reply , This my solustion : WinApi::CreateDirectoryPathUNC (path);

    public client static boolean CreateDirectoryPathUNC (FilePath _path)

    {

       int ptr;

       ;

       try

       {

           //First check for the passed path exits or not

           if (winAPI::folderExists(_path))

           {

               return true;

           }

           _path = strLRTrim(_path);

           if (substr(_path,strlen(_path),1) != '\\') //Adding backslash gives a more simple while-loop!

           {

               _path += '\\';

           }

           //enables creation of UNC paths, by detecting which folder already exists (backwards).

           ptr = strLen(_path);

           ptr = strfind(_path, '\\', ptr, -ptr);

           while(!WinAPI::folderExists(substr(_path,1,ptr)))

           {

               ptr = strfind(_path, '\\', ptr -1 , -ptr);

           }

           // ptr now points to last existing folder in the path.

           while (ptr)

           {

               WinAPI::createDirectory(substr(_path, 1, ptr));

               if (!WinAPI::folderExists(substr(_path, 1, ptr)))

               {

                   break;

               }

               ptr = strfind(_path, '\\', ptr + 1, strlen(_path));

           }

           return WinAPI::folderExists(_path);

       }

       catch

       {

           info('Folder path is not created.');

           return false;

       }

    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans