#!/usr/bin/perl # # Create a graph from a filesystem tree. # # usage: graphdir.pl # # Copyright (C) 2006 Alessandro Dotti Contra # Released under the terms of the GNU GPL. use warnings; use GraphViz; sub creategraph($$); my $image = "graph.png"; die "usage: graphdir.pl \n" if scalar(@ARGV) != 1; my $dir = shift; my $g = GraphViz->new(); open(IMG, ">$image") or die "Can't create graph: $!\n"; creategraph($g, $dir); print IMG $g->as_png(); close(IMG); exit 0; sub creategraph($$) { # Create a graph of the given directory and add an edge # to the parent directory my ($graph, $dir) = @_; my $parent = $dir; opendir(DIR, "$dir") or die "Can't open $dir: $!\n"; $graph->add_node($dir); chdir $dir; my @items = readdir(DIR); foreach my $item (sort @items) { next if $item =~ /^\./; if( -d $item) { $graph->add_node( $item, shape => 'box', color => 'red', fontsize => 10 ); creategraph($graph, $item); } if( -f $item) { $graph->add_node( $item, fontsize => 8 ); } $graph->add_edge($parent => $item); } chdir ".."; return; }