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
#6
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)
Reply


Messages In This Thread
RE: Browse and build a list of folder paths using recursion - by ibreeden - Apr-24-2021, 08:29 AM

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 1,494 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
Question Keyword to build list from list of objects? pfdjhfuys 3 2,631 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  python-docx regex : Browse the found words in turn from top to bottom Tmagpy 0 2,285 Jun-27-2022, 08:45 AM
Last Post: Tmagpy
  pdf2image, poppler and paths jehoshua 18 26,973 Jun-14-2022, 06:38 AM
Last Post: jehoshua
  Windows paths issue otalado 3 2,372 May-29-2022, 09:11 AM
Last Post: snippsat
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 6,361 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 3,139 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  automatically get absolute paths oclmedyb 1 3,882 Mar-11-2021, 04:31 PM
Last Post: deanhystad
  Using recursion instead of for loops / list comprehension Drone4four 4 5,148 Oct-10-2020, 05:53 AM
Last Post: ndc85430
  chkFile with absolute paths JarredAwesome 7 4,220 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