Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $no_of_args = @ARGV;
- $expand_size = 5;
- $max_width = 10;
- if(($no_of_args == 0) || ($no_of_args == 2))
- {
- print "ERROR: Insufficient argument\n";
- goto help;
- }
- elsif($no_of_args == 3)
- {
- if($ARGV[1] !~ "-width")
- {
- print "ERROR: Invalid argument\n";
- goto help;
- }
- elsif(($ARGV[2] > $max_width) || ($ARGV[2] < 2))
- {
- print "ERROR: Width should not lie outside 2 to $max_width.\n";
- goto help;
- }
- else
- {
- $expand_size = $ARGV[2];
- }
- }
- $dir_path = $ARGV[0];
- if(!(-d $dir_path))
- {
- print "ERROR: $dir_path doesn't exist\n";
- goto help;
- }
- if(($dir_path =~ /^\.$/) || ($dir_path =~ /^\.\/$/) || ($dir_path =~ /^\.\\$/))
- {
- $string = `cd`;
- $dir_name = $string;
- $dir_path = $string;
- }
- else
- {
- $dir_name = "$dir_path\n";
- }
- @array = `dir /B /S $dir_path`;
- $array_size = @array;
- $line_count = 0;
- while($line_count < $array_size)
- {
- $array[$line_count] =~ s/\\/\//g;
- $line_count ;
- }
- $line_count = 0;
- print " ----$dir_name";
- $temp = $dir_path;
- chop($temp);
- $temp =~ s/\\/\//g;
- while($line_count < $array_size)
- {
- if($array[$line_count] =~ /$temp\/(.*)/)
- {
- $array[$line_count] = "--$1\n";
- }
- $array[$line_count] =~ s/.[^\/]*\//--/g;
- $line_count ;
- }
- $line_count = 0;
- while($line_count < $array_size)
- {
- $array[$line_count] = "\|\-".$array[$line_count];
- $string = " " x ($expand_size - 1);
- while($array[$line_count] =~ /--/)
- {
- $array[$line_count] =~ s/--//;
- $array[$line_count] =~ s/\|\-/|$string|-/;
- }
- $string = "-" x ($expand_size - 1);
- $array[$line_count] =~ s/\-/$string/;
- $array[$line_count] =~ s/\|$string/\ $string/;
- $line_count ;
- }
- @cross = 0;
- $line_count = 0;
- while($line_count < $array_size)
- {
- $line = $array[$array_size - $line_count - 1];
- @line_array = split(//, $line);
- $no_of_char = @line_array;
- $char_count = 0;
- while($char_count < $no_of_char)
- {
- if($line_array[$char_count] =~ /\ /)
- {
- $cross[$char_count] = 1;
- }
- elsif($line_array[$char_count] =~ /\|/)
- {
- if($cross[$char_count] == 0)
- {
- $line_array[$char_count] = " ";
- }
- }
- else
- {
- $cross[$char_count] = 0;
- }
- $char_count = $char_count $expand_size;
- }
- $array[$array_size - $line_count - 1] = join("", @line_array);
- $line_count ;
- }
- print @array;
- exit;
- help:
- printf("#####################################################################\n");
- printf("# To run the script,\n");
- printf("# perl $0 <PATH> -width <width_no>\n");
- printf("# e.g. \"perl $0 . \" displays tree view of current dir\n");
- printf("# \"-width\" expand or compress the tree. Max = $max_width, Min = 2\n");
- printf("# Don't give relative path.....\n");
- printf("# Default width = 5\n");
- printf("#####################################################################\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement