Python Forum
Browse and build a list of folder paths using recursion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Browse and build a list of folder paths using recursion
#8
(Apr-24-2021, 08:29 AM)ibreeden Wrote: Well then there is only one way left: we introduce an extra parameter: "superfolder". What is a superfolder? Well everybody knows what a subfolder is: a folder below the current folder. So a superfolder is the opposite: the folder(path) above.
ServerName = "LINX-7912 Server"
root = ""
 
def BrowseServer(server,root, superfolder = ""):
    #print 'started BrowseServer(%s,%s)' % (server,root)
    path_list = []
    browseServer = system.opc.browseServer(server,root)
    for browse_object in browseServer:
        nodeName = str(browse_object.getDisplayName())
        nodeId = str(browse_object.getServerNodeId().getNodeId())
        elementType = str(browse_object.getElementType())
        if elementType == "OBJECT":
            fullpath = superfolder + "/" + nodeName
            print fullpath
            path_list.append(fullpath)
            path_list += BrowseServer(server, nodeId, fullpath)
    return path_list
 
obj_list = BrowseServer(ServerName,root)
print "\n"
for obj in obj_list:
    print obj
(I could not test it so I hope i made no mistakes)

This seemed to work minus the extra forward slash at the beginning, take a look at the image, once again look at the "OPC Browse" Pane towards the left to see the folder structure of the OPC Server "LINX-7912 Server!
You can see from the new image there're two root folders "Loytec ROOT" and "Server" with that said each OPC server could have a different amount of root folders? I could easily strip the first forward slash, or modify.

[Image: Vkc9I.png]
Reply


Messages In This Thread
RE: Browse and build a list of folder paths using recursion - by Ultrainstinct_5 - Apr-24-2021, 01:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 730 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
Question Keyword to build list from list of objects? pfdjhfuys 3 1,734 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  python-docx regex : Browse the found words in turn from top to bottom Tmagpy 0 1,625 Jun-27-2022, 08:45 AM
Last Post: Tmagpy
  pdf2image, poppler and paths jehoshua 18 16,063 Jun-14-2022, 06:38 AM
Last Post: jehoshua
  Windows paths issue otalado 3 1,574 May-29-2022, 09:11 AM
Last Post: snippsat
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,724 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,581 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  automatically get absolute paths oclmedyb 1 2,231 Mar-11-2021, 04:31 PM
Last Post: deanhystad
  Using recursion instead of for loops / list comprehension Drone4four 4 3,300 Oct-10-2020, 05:53 AM
Last Post: ndc85430
  chkFile with absolute paths JarredAwesome 7 3,153 Sep-21-2020, 03:51 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020