|
Nov
27
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | #!/usr/bin/perl -w # order templates, do NOT modify this annotation! ## #.<SELF>/#--<SELF>/#_<SELF>/pic_#/file_#/<SELF>.#/<SELF>_#// sub is_num{ $temp = shift; return ($temp=~/^d+$/); } sub is_inArray{ ($ele,@arr) = @_; foreach (@arr){ return 1 if($ele eq $_); } return 0; } sub lettersAdd{ my($letters, $step) = @_; my $last = unpack("C",substr($letters,-1,1)) + $step; if($last > 122){ if(length($letters)>1){ $str = lettersAdd(substr($letters, 0, length($letters)-1), 1).pack("C",$last-26); } else { $str = "a".pack("C",$last-26); } } else { $str = substr($letters, 0, length($letters)-1).pack("C",$last); } return $str; } sub print_line{ ($str) = @_; print " | $str"; print " " x (59-length($str)); print "|n"; } sub pathOf{ $f=shift; if($f=~/^(.*)/.+$/){ return "$1/"; } return "./"; } sub clashOf{ $f=shift; $p=pathOf($f); $f=~s/$p//; if($f=~/^(.*)..*$/){ return $1; } return $f; } sub extOf{ $f=shift; $p=pathOf($f); $f=~s/$p//; if($f=~/^.*.(.*)$/){ return $1; } return ""; } sub main_menu{ print " n"; print " +------------------------------------------------------------+n"; print " | MAIN MENU |n"; print " +------------------------------------------------------------+n"; print " | 1. Modify Whole File Name |n"; print " | 2. Replace |n"; print " | 3. Change With Order Name |n"; print " | 4. Add |n"; print " | 5. Delete |n"; print " | 6. Extended Functions |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub whole{ print " n"; print " +------------------------------------------------------------+n"; print " | MODIFY WHOLE FILE NAME |n"; print " +------------------------------------------------------------+n"; print " | 1. Capitalize File Name |n"; print " | 2. Lowercase File Name |n"; print " | 3. Capitalize First Letter of Each Word of File Name |n"; print " | 4. Lowercase First Letter of Each Word of File Name |n"; print " | 5. Change File Name to |n"; print " | 6. Caplitalize Extension |n"; print " | 7. Lowercase Extension |n"; print " | 8. Change Extension to |n"; print " | |n"; print " | NOTE: File Name Does NOT Include Extension If Any |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub template{ print " n"; print " +------------------------------------------------------------+n"; print " | CHOOSE A ORDER TEMPLATE |n"; print " +------------------------------------------------------------+n"; print " | 1. Input A Template And Add It To The List |n"; print " | 2. Input A Template(Do Not Add To The List) |n"; for($i=0; $i<@ts; $i++){ print_line(($i+3).". ".$ts[$i]." "); } print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub get_pattern{ while(1){ print " >> Input a pattern: "; chomp ($the_p = <STDIN>); if($the_p =~ /^/(.+)/$/){ $the_p = $1; last; } else { print " !! The pattern is like [/txt/] .n"; } } return $the_p; } sub get_replace{ while(1){ print " >> Input a replace string: "; chomp ($the_p = <STDIN>); if($the_p =~ /^[^/]+$/){ last; } else { print " !! [/] is not allowed.n"; } } return $the_p; } sub input{ print " n"; print " +------------------------------------------------------------+n"; print " | INPUT FILES |n"; print " +------------------------------------------------------------+n"; print " | 1. Input A Path And A Filter |n"; print " | 2. Input Files Directly |n"; print " | |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub preview_or_apply{ print " n"; print " +------------------------------------------------------------+n"; print " | PREVIEW OR APPLY |n"; print " +------------------------------------------------------------+n"; print " | 1. Preview |n"; print " | 2. Apply |n"; print " | |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub help{ ($last_menu) = @_; print " n"; print " +------------------------------------------------------------+n"; print " | HELP |n"; print " +------------------------------------------------------------+n"; print " | INPUT FILES: |n"; print " | 1. Input A Path And A Filter |n"; print " | Input a path: |n"; print " | 1) path must exist |n"; print " | 2) path can be either relative or absolute |n"; print " | 3) enter directly for current directory |n"; print " | Input a filter: |n"; print " | 1) between // is a regular expression |n"; print " | 2) front ! means except files meet the given pattern |n"; print " | 3) enter directly for all the files |n"; print " | /.*.txt/ all .txt files |n"; print " | !/.*.txt/ all files but .txt |n"; print " | 2. Input Files Directly |n"; print " | 1) folder:foo1|foo2|foo3 |n"; print " | for file 'foo1' 'foo2' 'foo3' in the same 'folder' |n"; print " | 2) folder/foo1|folder/foo2|folder/foo3 |n"; print " | for the same |n"; print " | |n"; print " | MAIN MENU |n"; print " | 1. Modify Whole File Name |n"; print " | 1) extension treated as a separate part |n"; print " | 2) '/' is not allowed in file name and extension |n"; print " | 2. Replace |n"; print " | 1) replace pattern should be a regular expression |n"; print " | with '//' |n"; print " | 2) '/' is not allowed in replace string |n"; print " | e.g.: foo1,foo2,foo3 -> foo2,foo3,foo4 |n"; print " | pattern: /(d+)/ , replace string: ($1+1)."_" |n"; print " | then foo1,foo2,foo3 -> foo2_,foo3_,foo4_ |n"; print " | and then delete '_'(use function delete) |n"; print " | 3. Change With Order Name |n"; print " | 1) template |n"; print " | <SELF> represents file name (exclude extension) |n"; print " | # for digits or characters to replace, it's required |n"; print " | 2) the template will add to the list after you restart |n"; print " | this program if you choose this option |n"; print " | 3) regulation of order |n"; print " | 'a,b,c,d,e' |n"; print " | all can be omitted, the default value is '0,1,1,0,0' |n"; print " | a: start number or letter of order |n"; print " | b: number only, step of orde |n"; print " | c: maximal digit of number ignored if d set to 0 |n"; print " | d: 1, fill other digit 'a'(for letter) or '0'(for |n"; print " | number) if total digits less than maximum while |n"; print " | 0 does NOT |n"; print " | e: if letters capitalize them |n"; print " | 4. Add |n"; print " | Input position and string to add |n"; print " | 'pos/str' |n"; print " | pos: add position, e.g.: '0' for front ; |n"; print " | '1' for position between 1st and 2nd letter |n"; print " | '-1' between last letter and letter before it |n"; print " | str: string to add, '/' is not allowed |n"; print " | 5. Delete |n"; print " | 1) input a string to delete |n"; print " | 'foo' or 'foo/0' or 'foo/1' |n"; print " | 'foo' is an omitted form of 'foo/0' |n"; print " | '/0' means delete the first 'foo' in file name |n"; print " | '/1' means delete all 'foo' in file name |n"; print " | 2) input position and length to delete |n"; print " | 'pos/len' |n"; print " | pos is as the same as it in 'Add' menu |n"; print " | |n"; print " | !X !S. Goto Previous Menu |n"; print " | S. Save This Help to File 'smartrename.help' |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; if($_ eq "X"){ print "n"; exit; } elsif($_ eq "S"){ open(H, ">smartrename.help"); print H " n"; print H " +------------------------------------------------------------+n"; print H " | HELP |n"; print H " +------------------------------------------------------------+n"; print H " | INPUT FILES: |n"; print H " | 1. Input A Path And A Filter |n"; print H " | Input a path: |n"; print H " | 1) path must exist |n"; print H " | 2) path can be either relative or absolute |n"; print H " | 3) enter directly for current directory |n"; print H " | Input a filter: |n"; print H " | 1) between // is a regular expression |n"; print H " | 2) front ! means except files meet the given pattern |n"; print H " | 3) enter directly for all the files |n"; print H " | /.*.txt/ all .txt files |n"; print H " | !/.*.txt/ all files but .txt |n"; print H " | 2. Input Files Directly |n"; print H " | 1) folder:foo1|foo2|foo3 |n"; print H " | for file 'foo1' 'foo2' 'foo3' in the same 'folder' |n"; print H " | 2) folder/foo1|folder/foo2|folder/foo3 |n"; print H " | for the same |n"; print H " | |n"; print H " | MAIN MENU |n"; print H " | 1. Modify Whole File Name |n"; print H " | 1) extension treated as a separate part |n"; print H " | 2) '/' is not allowed in file name and extension |n"; print H " | 2. Replace |n"; print H " | 1) replace pattern should be a regular expression |n"; print H " | with '//' |n"; print H " | 2) '/' is not allowed in replace string |n"; print H " | e.g.: foo1,foo2,foo3 -> foo2,foo3,foo4 |n"; print H " | pattern: /(d+)/ , replace string: ($1+1)."_" |n"; print H " | then foo1,foo2,foo3 -> foo2_,foo3_,foo4_ |n"; print H " | and then delete '_'(use function delete) |n"; print H " | 3. Change With Order Name |n"; print H " | 1) template |n"; print H " | <SELF> represents file name (exclude extension) |n"; print H " | # for digits or characters to replace, it's required |n"; print H " | 2) the template will add to the list after you restart |n"; print H " | this program if you choose this option |n"; print H " | 3) regulation of order |n"; print H " | 'a,b,c,d,e' |n"; print H " | all can be omitted, the default value is '0,1,1,0,0' |n"; print H " | a: start number or letter of order |n"; print H " | b: number only, step of orde |n"; print H " | c: maximal digit of number ignored if d set to 0 |n"; print H " | d: 1, fill other digit 'a'(for letter) or '0'(for |n"; print H " | number) if total digits less than maximum while |n"; print H " | 0 does NOT |n"; print H " | e: if letters capitalize them |n"; print H " | 4. Add |n"; print H " | Input position and string to add |n"; print H " | 'pos/str' |n"; print H " | pos: add position, e.g.: '0' for front ; |n"; print H " | '1' for position between 1st and 2nd letter |n"; print H " | '-1' between last letter and letter before it |n"; print H " | str: string to add, '/' is not allowed |n"; print H " | 5. Delete |n"; print H " | 1) input a string to delete |n"; print H " | 'foo' or 'foo/0' or 'foo/1' |n"; print H " | 'foo' is an omitted form of 'foo/0' |n"; print H " | '/0' means delete the first 'foo' in file name |n"; print H " | '/1' means delete all 'foo' in file name |n"; print H " | 2) input position and length to delete |n"; print H " | 'pos/len' |n"; print H " | pos is as the same as it in 'Add' menu |n"; print H " | |n"; print H " +------------------------------------------------------------+n"; print H " n"; close(H); print " >> [smartrename.help] saved!n"; return $last_menu; } else { return $last_menu; } } sub deletion{ print " n"; print " +------------------------------------------------------------+n"; print " | DELETE OPTIONS |n"; print " +------------------------------------------------------------+n"; print " | 1. Input String to Delete |n"; print " | 2. Extended Deletion |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub extend{ print " n"; print " +------------------------------------------------------------+n"; print " | EXTENDED FUNCTIONS |n"; print " +------------------------------------------------------------+n"; print " | 1. Reverse English Characters Case |n"; print " | 2. Reverse Characters Order |n"; print " | 3. Lowercase Letter After Capital Letter One By One |n"; print " | Like: AaBbCcDdEeFf |n"; print " | 4. Capital Letter After Lowercase Letter One By One |n"; print " | Like: aAbBcCdDeEfF |n"; print " | 5. The 1st Choice Act On Extension |n"; print " | 6. The 2nd Choice Act On Extension |n"; print " | 7. The 3rd Choice Act On Extension |n"; print " | 8. The 4th Choice Act On Extension |n"; print " | |n"; print " | U. Goto Previous Menu |n"; print " | M. Goto Main Menu |n"; print " | H. Help |n"; print " | X. Exit |n"; print " +------------------------------------------------------------+n"; print " n"; print " >> Your choice: "; $_=<STDIN>; chomp; return $_; } sub get_delete_string{ while(1){ print " >> Input a string to delete: "; chomp ($_ = <STDIN>); if(/^[^/]+(?:/(?:0|1))?$/){ last; } else { print " !! [foo/0] to delete [foo] once while [foo/1] delete all.n"; } } return $_; } sub get_extended_deletion{ while(1){ print " >> Input position and length to delete: "; chomp ($_ = <STDIN>); if(/^d+/d+$/){ last; } else { print " !! [0/2] to delete the first 2 characters.n"; } } return $_; } sub get_menu{ ($menu) = @_; $ubound = $m_ubound{$menu}; @chars = split /,/, $m_chars{$menu}; while(1){ $choice = $menu; if(is_num $choice){ if($choice>=1 and $choice<=$ubound){ last; } else { print " !! Unknown choice.n"; } } else { if($choice eq "X" and is_inArray("X", @chars)){ print "n"; exit; } elsif($choice eq "H" and is_inArray("H", @chars)){ return get_menu(help($menu)); } elsif($choice eq "M" and is_inArray("M", @chars)) { return get_menu("main_menu"); } elsif($choice eq "U" and is_inArray("U", @chars)){ goto RESTART if($m_prev{$menu} eq "input"); goto REDO if($m_prev{$menu} eq "main_menu"); return get_menu($m_prev{$menu}); } else { print " !! Unknown choice.n"; } } } return $choice; } sub get_path{ while(1){ print " >> Input a path: "; $the_path = <STDIN>; chomp $the_path; return "./" if($the_path=~/^s*$/); # if no input, set path current directory if(-e $the_path and -d $the_path){ last; } else { print " !! Nonexistent path or non-directory path. n" } } return $the_path."/" if($the_path=~/^.*[^/]$/); return $the_path; } sub get_filter{ while(1){ print " >> Input a filter: "; $the_filter = <STDIN>; chomp $the_filter; if($the_filter=~/^!?/.+/$/){ last; } elsif($the_filter=~/^s*$/){ # for all the files $the_filter = "/^.*$/"; last; }else { print " !! The filter pattern is [!?/.+/] , e.g.:n"; print " !! [!/.*.txt/] for all but .txt files.n"; } } return $the_filter; } sub get_files{ REENTER:while(1){ print " >> Input files: "; $the_files = <STDIN>; chomp $the_files; ($the_path, $the_files) = ($the_files=~/^(?:(.+)s*:s*)?(.+)$/); if(!defined($the_files)){ print " !! Please check if [$_] exists, input sample: n"; print " !! [test:1.txt|2.txt] for 1.txt and 2.txt in directory;n"; print " !! [test/1.txt|test/2.txt] for the same.n"; next; } @the_filess = split /s*|s*/, $the_files; foreach (@the_filess){ if(defined($the_path)){$_ = "$the_path/$_";} if(!-e $_){ print " !! Please check if [$_] exists, input sample: n"; print " !! [test:1.txt|2.txt] for 1.txt and 2.txt in directory;n"; print " !! [test/1.txt|test/2.txt] for the same.n"; next REENTER; } } last; } return @the_filess; } sub get_if_apply{ while(1){ print " >> Apply(y) or discard(n) the results? "; $the_apply = <STDIN>; chomp $the_apply; if($the_apply eq "y" or $the_apply eq "n"){ last; } else { print " !! Input [y] or [n].n"; } } return $the_apply; } sub get_file_or_ext{ $flag = shift; $f = $flag ? "file name" : "extension"; while(1){ print " >> Input a new $f: "; $the_f = <STDIN>; chomp $the_f; if($the_f =~ /^[^/]+$/){ last; } else { print " !! [/] is not allowed in $f.n"; } } return $the_f; } sub get_input_template{ while(1){ print " >> Input a new template: "; chomp ($the_t = <STDIN>); if($the_t =~ /^[^/]*#[^/]*$/){ last; } else { print " !! [#] is required and [/] is not allowed.n"; } } return $the_t; } sub get_template{ $temp_choice = get_menu("template"); if($temp_choice == 1){ $temp = get_input_template; open(SELF, "$0"); @self_content = <SELF>; close(SELF); open(SELFBAK, ">$0.bak"); print SELFBAK @self_content; close(SELFBAK); foreach (@self_content){ if(/^## .+///){ s/////$temp///; } if(/^s+template => (d+),/){ s/($1)/$1+1/e; last; } } open(SELF, ">$0"); print SELF @self_content; close(SELF); } elsif ($temp_choice == 2){ $temp = get_input_template; } else { $temp = $ts[$temp_choice - 3]; } return $temp; } sub get_regular{ while(1){ print " >> Input A Regulation of Order: "; chomp ($_ = <STDIN>); if(/^(?:d+|[a-z]+)?(?:,d+)?(?:,d+)?(?:,(?:0|1))?(?:,(?:0|1))?$/){ last; } else { print " !! e.g.: [a,1,2,1,1] makes orders AA, AB, AC....n"; } } return $_; } sub get_add{ while(1){ print " >> Input position and string to add: "; chomp ($_ = <STDIN>); if(/^-?d+/[^/]+$/){ last; } else { print " !! e.g.: [0/foo] to add [foo] to the front.n"; } } return $_; } %m_ubound = ( input => 2, main_menu => 6, whole => 8, preview_or_apply =>2, template => 12, deletion => 2, extend => 8, ); %m_prev = ( main_menu => "input", whole => "main_menu", template => "main_menu", deletion => "main_menu", extend => "main_menu", ); %m_chars = ( input => "H,X", main_menu => "U,H,X", whole => "U,M,H,X", template => "U,M,H,X", deletion => "U,M,H,X", extend => "U,M,H,X", preview_or_apply => "H,X", ); open(SELF, $0); while(<SELF>){ chomp; if($_ =~ /^## (.+)///){ @ts = split ///, $1; last; } } close(SELF); RESTART: $input_menu = get_menu("input"); @files = (); %out_files = (); # get input files if($input_menu==1){ $path = &get_path; $filter = &get_filter; opendir(DIR, $path); while($file=readdir(DIR)){ if($filter=~/^!/(.+)/$/){ push @files,$path.$file if($file!~/$1/ and $file ne "." and $file ne ".."); } elsif($filter=~/^/(.+)/$/) { push @files,$path.$file if($file=~/$1/ and $file ne "." and $file ne ".."); } } closedir(DIR); } else { @files = &get_files; } print " n"; print " +------------------------------------------------------------+n"; print " | FILES TO RENAME |n"; print " +------------------------------------------------------------+n"; foreach (sort {lc($a) cmp lc($b) or $a <=> $b} @files){print_line($_);} print " +------------------------------------------------------------+n"; REDO: $main_input = get_menu("main_menu"); if($main_input==1){ $whole_choice = get_menu("whole"); if($whole_choice==1){ foreach (@files){ $out_files{$_} = pathOf($_).uc(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==2){ foreach (@files){ $out_files{$_} = pathOf($_).lc(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==3){ foreach (@files){ $out_files{$_} = pathOf($_).ucfirst(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==4){ foreach (@files){ $out_files{$_} = pathOf($_).lcfirst(clashOf($_)).((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==5){ $file_name = get_file_or_ext(1); foreach (@files){ $out_files{$_} = pathOf($_).$file_name.((extOf($_) ne "")?".":"").extOf($_); } } elsif($whole_choice==6){ foreach (@files){ $out_files{$_} = pathOf($_).clashOf($_).((extOf($_) ne "")?".":"").uc(extOf($_)); } } elsif($whole_choice==7){ foreach (@files){ $out_files{$_} = pathOf($_).clashOf($_).((extOf($_) ne "")?".":"").lc(extOf($_)); } } elsif($whole_choice==8){ $file_name = get_file_or_ext(0); foreach (@files){ $out_files{$_} = pathOf($_).clashOf($_).((extOf($_) ne "")?".":"").((extOf($_) ne "")?$file_name:""); } } } elsif ($main_input== 2){ $pattern = get_pattern; $replace = get_replace; foreach (@files){ $file_name = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); #$file_name =~ s/$pattern/($replace=~s/<(d+)>/$$1/g)/e; #eval('$file_name =~ s/$pattern/$replace/e;'); if($replace =~ /$/){ $file_name =~ s/$pattern/eval($replace)/e; } else { $file_name =~ s/$pattern/$replace/; } $out_files{$_} = pathOf($_).$file_name; } } elsif ($main_input==3){ $tmp = get_template; $reg = get_regular; ($start, $step, $len, $iffill, $ifcap) = ($reg =~ /^(d+|[a-z]+)?(?:,(d+))?(?:,(d+))?(?:,(0|1))?(?:,(0|1))?$/); $start = 0 if(!defined($start)); $step = 1 if(!defined($step)); $len = 1 if(!defined($len)); $iffill = 0 if(!defined($iffill)); $ifcap = 0 if(!defined($ifcap)); foreach (@files){ $tmp_clash = $tmp; $clash = clashOf($_); if($iffill){ if(length($start)<$len){ $start = sprintf(is_num($start)?"0":"a" x ($len-length($start))).$start; } } if(!is_num($start)){ if($ifcap) {$start = uc($start);} else {$start = lc($start);} } $tmp_clash =~ s/#/$start/g; $tmp_clash =~ s/<SELF>/$clash/g; $out_files{$_} = pathOf($_).$tmp_clash.((extOf($_) ne "")?".":"").extOf($_); if(is_num($start)){ $start += $step ; } else { $start = lettersAdd(lc($start), $step); } } } elsif ($main_input==4){ $add = get_add; ($pos, $str) = ($add =~ /^(-?d+)/([^/]+)$/); foreach (@files){ $clash = clashOf($_); substr($clash,$pos,0) = $str; $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($main_input==5){ $delete = get_menu("deletion"); if($delete == 1){ $d_str = get_delete_string; ($delete_str, $delete_global) = ($d_str =~ /^([^/]+)(?:/(0|1))?$/); $delete_global = 0 if(!defined($delete_global)); foreach (@files){ $clash = clashOf($_); if($delete_global){ $clash =~ s/$delete_str//g; } else { $clash =~ s/$delete_str//; } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } else { $d_ext = get_extended_deletion; ($d_pos,$d_len) = ($d_ext =~ /^(d+)/(d+)$/); foreach (@files){ $clash = clashOf($_); substr($clash,$d_pos,$d_len) = ""; $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } } else { $e_choice = get_menu("extend"); if($e_choice == 1){ foreach (@files){ $clash = clashOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); substr($clash,$i,1) = $c eq lc($c)?uc($c):lc($c); } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 2){ foreach (@files){ $clash = clashOf($_); $clash = reverse(split //,$clash); $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 3){ foreach (@files){ my $first_cap = 1; $clash = clashOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 4){ foreach (@files){ my $first_cap = 0; $clash = clashOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash.((extOf($_) ne "")?".":"").extOf($_); } } elsif ($e_choice == 5){ foreach (@files){ $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); substr($clash,$i,1) = $c eq lc($c)?uc($c):lc($c); } $out_files{$_} = pathOf($_).$clash; } } elsif ($e_choice == 6){ foreach (@files){ $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); $clash = reverse(split //,$clash); $out_files{$_} = pathOf($_).$clash; } } elsif ($e_choice == 7){ foreach (@files){ my $first_cap = 1; $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash; } } else { foreach (@files){ my $first_cap = 0; $clash = clashOf($_).((extOf($_) ne "")?".":"").extOf($_); for(my $i=0; $i<length($clash); $i++){ my $c = substr($clash,$i,1); if(uc($c) ne lc($c)){ substr($clash,$i,1) = $first_cap?uc($c):lc($c); $first_cap = !$first_cap; } } $out_files{$_} = pathOf($_).$clash; } } } $app_input = get_menu("preview_or_apply"); if($app_input==1){ print "n"; print " +------------------------------------------------------------+n"; print " | RESULTS PREVIEW |n"; print " +------------------------------------------------------------+n"; foreach (sort {lc($a) cmp lc($b) or $a <=> $b} keys %out_files){ print " = [$_] => [$out_files{$_}]n"; } print " +------------------------------------------------------------+nn"; $app_choice = get_if_apply; if($app_choice eq "n"){ goto REDO; } } print "n"; print " +------------------------------------------------------------+n"; print " | RESULTS APPLYING |n"; print " +------------------------------------------------------------+n"; foreach (sort {lc($a) cmp lc($b) or $a <=> $b} keys %out_files){ if(!-e $out_files{$_} and rename($_,$out_files{$_})){ print " ~ "; } else { print " ! "; } print "[$_] => [$out_files{$_}]n"; } print " +------------------------------------------------------------+n"; print "n >> Done! n"; goto RESTART; |
这篇文章来自 迷途知返(PWWANG.COM), 转载请注明出处。 版权说明
Leave a comment
| Trackback

