Last active
October 29, 2022 02:16
-
-
Save radixvinni/54087bdeeaf5fe99fa02 to your computer and use it in GitHub Desktop.
Plot directory or file tree structure graph with graphviz neato
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# dir2dot.pl v0.5 (C) [email protected], released under the GPL. | |
# Download from: http://www.chaosreigns.com/code/ | |
# | |
# Generates a directed graph of a directory tree using graphviz like so: | |
# | |
# find . -type d -print | perl dir2dot.pl > dirtree.dot | |
# neato -Tpng dirtree.dot > dirtree.png | |
# | |
# Graphviz can be downloaded from: http://www.research.att.com/sw/tools/graphviz/ | |
while ($line = <STDIN>) | |
{ | |
chomp $line; | |
$target_name=$line; | |
@target = split(/\//,$line); | |
$target_label = (reverse(@target))[0]; | |
$#target--; | |
$source_name = join('/',@target); | |
next if $target_name eq ''; | |
$source_name = '/' if $source_name eq ""; | |
$target_label = '/' if $target_label eq ""; | |
push (@nodes,"\"$target_name\" [label=\"$target_label\"]"); | |
$edges{$target_name} = $source_name; | |
} | |
print "digraph \"directory tree\" {\n"; | |
print join("\n",@nodes),"\n"; | |
for $key (sort keys %edges) | |
{ | |
print "\"$edges{$key}\" -> \"$key\" [len=3]\n"; | |
} | |
print "}\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment