January 25, 2011

Visualizing directories and files as a graph

The Information Retrieval class I have been taking this spring has been inspiring me to try quite a few things, the first of them was to try and analyse text to extract the semantic information in the words. Well that has not reached anywhere near perfection but the present code for a naive method of drawing a graph containing the words can be found here. While trying to draw the graph for the words, I did however read through the NetworkX library documentation extensively. I really like this library, creating simple graphs is very easy and at the same time there are so many features if you want to do a lot more with the graph. While I was searching for some interesting problem which I could visualize as a graph (just to flex my python skills and to get more fluent with NetworkX), the idea of trying to see a directory as a graph with files and sub-directories as nodes colored by the file type struck, especially I wanted to try this out on the directory where I store all my work related files, and here is the result :

well , the above code is simple directory traversal in python with the code for drawing the graph added. (the script works only on *nix systems and ignores hidden files and directories by default, this is so that I could ignore the nasty version control related metadata directories like .git or .svn which are quite common in my folders).
The graph without the file names produced by the script looks like this :

The other files and graphs can be found here.