Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

create folder in device tree

mvs
2015-04-21
2015-04-21
  • mvs - 2015-04-21

    Hi there,

    I am new to Python programming and have a small issue, maybe:

    How can I create a new folder in the device-tree or the POU-tree?

    For example:
    I want to create a new folder at: "Application/POUs" that should be named with "test".
    So that I have a new folder at: "Application/POUs/test" where I can import any POUs.

    Is that possible?
    If yes might an example very helpfull.

    Regards
    Michael

     
  • mkeller - 2015-04-21

    Hi mvs.

    A script object can create a folder under itself by calling the method create_folder(<folder name="">). See example.</folder>

    proj = projects.primary
    objs = proj.find('Folder', recursive = True)
    folder = objs[0]
    folder.create_folder('SubFolder')
    objs = folder.find('SubFolder')
    if not objs[0].is_folder:
    Β  Β raise Exception('Object is not a folder')
    

    BR
    Martin

     
  • mvs - 2015-04-21

    Hi Martin,

    I tested it and it works great.

    Many thanks

    Michael

     

Log in to post a comment.