Proiect Semestru CI
Silviu Ivan 452A
Se testeaza apasand aici
Codul sursa este urmatorul :
$primary_path = $ENV{'DOCUMENT_ROOT'}; if(-d $ENV{'QUERY_STRING'}) { $primary_path = $ENV{'QUERY_STRING'}; } print "Pragma: no-cache\nContent-type: text/html\n\n"; print qq~Script Perl de listare a fisierelor Scriptul meu ruleaza pe serverul : $ENV{'SERVER_NAME'} ~; my(%dirs, %dirs2beread, %dirs2bexfer, %ascii2bexfer, %binary2bexfer, %filesoftype); my($total_dirs, $total_ascii, $total_binary, $total_files, $total_size); $dirs{$primary_path} = 1; $dirs2beread{$primary_path} = 1; my $read_dirs = 1; while($read_dirs) { my @dirkeys = sort keys %dirs2beread; my $this_dir = shift(@dirkeys); delete $dirs2beread{$this_dir}; my @new = &readit($this_dir); foreach(@new) { if(-d $_) { $dirs{$_} = 1; $dirs2beread{$_} = 1; $dirs2bexfer{$_} = 1; $total_dirs++; } elsif(-T $_) { $ascii2bexfer{$_} = 1; $total_ascii++; $total_files++; } else { $binary2bexfer{$_} = 1; $total_binary++; $total_files++; } unless(-d $_) { $total_size += (-s $_); my @breakitup = split(/\//, $_); my @ext; if($breakitup[$#breakitup] =~ /\./) { @ext = split(/\./, $breakitup[$#breakitup]); } else { $ext[0] = 'No Extension'; } $filesoftype{$ext[$#ext]}++; } } my @checkloop = keys %dirs2beread; unless((-d $checkloop[0]) && ($checkloop[0] =~ /[a-zA-Z1-9]/)) { $read_dirs = 0; } } $total_size = sprintf("%5.2d", int(($total_size / 1024) + .5)); my $type_summary = qq~~; my $add_new_row = 0; for(sort keys %filesoftype) { $add_new_row++; if($add_new_row % 5 == 0) { $type_summary .= qq~~; } $type_summary .= qq~.$_: $filesoftype{$_}~; } $type_summary .= qq~ ~ x ($add_new_row % 5); $type_summary .= qq~~; #Print out the counts print qq~ Directories: $total_dirs | ASCII: $total_ascii | Binary: $total_binary | Files: $total_files | Total Size: $total_size Kb. $type_summary ~; #Finally, print out everything sorted by directory. my @all_items = sort {$a cmp $b} keys %dirs; for(my $a = 0; $a <= $#all_items; $a++) { my @get_files = grep { /^$all_items[$a]\/([^\/])+$/ } keys %ascii2bexfer; push(@get_files, grep { /^$all_items[$a]\/([^\/])+$/ } keys %binary2bexfer); $all_items[$a] =~ s/$primary_path//; $all_items[$a] ||= '/'; print qq~$all_items[$a]\n\n~; my @sorted_files = sort @get_files; for(my $b = 0; $b <= $#sorted_files; $b++) { $sorted_files[$b] =~ s/$primary_path//; print "$sorted_files[$b]\n"; } print "\n"; } print qq~ Script de test!! © 2005 Silviu Ivan