use strict; use warnings; sub blockrename { my @tmp = (); our @d_arr = &ci_sort(&br_readdir($main::dir)); my $dtext = join ("\n", @d_arr); my $top = $main::mw -> Toplevel(); $top -> title ( "Block Rename" ); our $txt = $top -> Scrolled ( 'ROText', -scrollbars=>"osoe", -width=>60, -height=>20, -font=>$main::dialog_font ) -> grid ( -row => 2, -column => 1, -columnspan => 1 ); $txt->menu(undef); $txt -> insert ( 'end', "$dtext" ); our $txt_r = $top -> Scrolled ( 'Text', -scrollbars=>"osoe", -width=>60, -height=>20, -font=>$main::dialog_font ) -> grid ( -row => 2, -column => 2, -columnspan => 2 ); $txt_r->menu(undef); $txt_r -> insert ( 'end', "$dtext" ); my $frm = $top -> Frame() -> grid ( -row => 4, -column => 1, -columnspan => 2, -sticky=>"ne" ); my $rename = $frm -> Button ( -text=>"Rename", -activebackground => 'white', -command => sub { &br(); } ) -> pack(-side => 'left'); my $but_reset = $frm -> Button ( -text=>"Reset", -activebackground => 'white', -command => \&txt_reset ) -> pack(-side => 'left'); my $but_close = $frm -> Button ( -text=>"Close", -activebackground => 'white', -command => sub { &ls_dir; destroy $top; } ) -> pack(-side => 'left'); $frm -> Button ( -text=>"Clear", -activebackground => 'white', -command => sub { $main::txt_r->delete('0.0','end'); } ) -> pack(-side => 'left'); $top->resizable(0,0); } sub txt_reset { @main::d_arr = &ci_sort(&br_readdir($main::dir)); my $dtext = join ("\n", @main::d_arr); $main::txt->delete('0.0','end'); $main::txt-> insert ( 'end', "$dtext" ); $main::txt_r->delete('0.0','end'); $main::txt_r-> insert ( 'end', "$dtext" ); } sub br { my @new_l = split(/\n/, $main::txt_r -> get('1.0', 'end')); my $c = 0; my $of = ""; my $nf = ""; my $max = $#main::d_arr; print "\@new_l: @new_l\n"; while($c <= $max) { $of = $main::d_arr[$c]; $nf = $new_l[$c]; $nf =~ s/\n|\r//g; $of =~ s/\n|\r//g; if(!$nf) # watch out for blank lines { return; } if($nf =~ m/^ed2k:\/\/\|file\|(.*?)\|/i) { $nf = $1; } $c++; print "$of -> $nf\n"; rename $of, $nf; } &txt_reset; return 0; } 1;