Generative Design Variations M.5.2 Reading data from the hard drive

This part of the tree diagram chapter is a bit different from the other ones. It’s about reading data from your own hard drive. I quote the Generative Design book: ‘The files in a folder on your hard drive serve as the data basis for the tree structures in this chapter. In the section ‘Collage from collection,’ we demonstrate how several files from one folder could be loaded. This exercise differs from that example in two ways. First, the ‘tree-structure’ within a folder is required for visualisation, meaning that for each folder, all subordinated files and folders have to be traversed recursively. Second, we are no longer interested in the actual file contents but rather only in information about the files, such as their size. In order to load and display a folder structure, a new data class FileSystemItem is created. Each instance of this class can contain any number of FileSystemItem instances. An output method in the FileSystemItem class is needed for an initial simple presentation of the processed tree structure. The printDepthFirst () function recursively processes and displays the entire tree structure in the Processing console with line indentation, which indicates the depth. The tree is processed according to the principle of depth-first search: the algorithm first goes into the depth of the leaves and then branch by branch into the width. The principle of depth-first search is the ‘natural’ way that a recursively defined function processes a hierarchical structure.’ That is what the Generative Design book tells me. If you would like to see the original code you can find it here.

Now the point is… there are no graphics involved. I only get feedback in the console window of the Processing Development Environment. So I think its best to write a bit more about what I did instead of showing a tree-structure in ASCII text. I started with looking for a folder which might be interesting to read. I copied my review of films folder to the desktop and specified the path of the default folder to that film review folder. Than I let the program run. The result is a terrible mess of folders and files. It is an ordered list but it looks very chaotic. But that is because my directory of films is chaotic? Maybe it’s still a good idea to show some screen dumps. It saves me a lot of writing and it shows the idea more clearly. Here is one:

M_5_2_01_GDV_01

Looking under the FileSystemItem tab I found the class FileSystemItem. It’s a class based on code and ideas of Ben Fry. I need to go a bit deeper into that before I can say something sensible about it. FileSystemItem looks for a file or folder. Found references to sub-objects are stored in the array children. It also sorts file names alphabetically. It skips . and .. directory entries and symbolic links. It also checks if the child elements exists. Aliases or shortcuts are skipped. And than a new instance of FileSystemItem is generated for all folders and files. But I needed a much more simpler directory. So I made a fake directory. The root folder is called FakeDirectory. And it contains four FakeFolders to begin with:

M_5_2_01_GDV_02

As I noticed the output gives me two representations of the same FakeDirectory. One is called printDepthFirst and the other one is printBreadthFirst. I was not familiar with these two sorting processes so I looked it up. Depth-first search starts at the root of the directory and then it searches as far as possible along each branch before going back. Breadth-first also starts it’s search at the root directory and then it tries to find the neighbor nodes first before ging into the next level of neighbours. You can see the differences in this screendump:

M_5_2_01_GDV_03

And that is (in short) what there is to tell about this exercise. There are some other issues which I did not mention. But I think I will use that fake directory in the next assignment. Don’t know if that will work but we will see. At this moment I think it’s best to start as simple as possible. Adding complexity later when it is needed.

Advertisements

Comments? Leave a reply.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s