Home Technical Talk

Python recursive nested arrays problem

polycounter lvl 8
Offline / Send Message
MaVCArt polycounter lvl 8
So I have a little problem in Python that I've been breaking my head over for the past few days and I simply can not seem to figure it out.

I'm working on an application that within its data structure mirrors windows explorer by iterating over a directory's contents, and storing every directory in it as a ProjectDir class instance that I can then access. If necessary this process can keep running until every directory is found, therefore listing every directory and every sub-directory, structured so that their hierarchy is the same as in windows. My problem however is in iterating over these directories.

For clarity's sake, this is an approximation of what the data looks like:

directory class instance
list of directories:
[dir class inst, dir class inst, dir class inst, ...]
list of files:
[file class inst, file class inst...]

I hope it's clear from that visualization, but my problem here is that i'm trying to iterate over potentially endlessly nested arrays, and I simply can not figure out an algorithm to do it.

The reason I need to iterate in this manner is because I need to print my folder structure in a PyQt TreeView, and duplicating windows' structure is the only way I know of doing that accurately

Replies

Sign In or Register to comment.