每次看到小伙伴Bulk Rename Utility 玩不转,手动对大量目录子目录下的文件进行加前缀、加后缀、替换、删除等改名操作,就非常心疼。
利用批处理对文件名进行操作。
操作文件前应当对原文件有备份,因为Windows系统对文件名排序这块是02
在1
之后。
保存代码到文件名操作.bat
执行,将要改动的文件所在目录拖放进来,按提示执行。
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 @echo off mode con cols=100 lines=38 color 02 title 文件名操作 by:小可(xianghongai@gmail.com)SETLOCAL ENABLEDELAYEDEXPANSION:GTBegin cls @echo 文件名操作 [前后缀、序数、替换、删除] @echo -------------------------------------------- @echo 所有操作按回车键 (Enter) 继续 @echo -------------------------------------------- set /p HandleDir=拖一个需处理的文件夹进来::GTCONTINUE cls @echo 文件名操作 @echo -------------------------------------------- @echo 处理的目录:%HandleDir% @echo . @echo -----------------1 .加前缀----------------- @echo 11 - 当前目录:目录名-文件名 @echo 12 - 层级子目录:子目录名-文件名 @echo 13 - 当前目录:前缀字符-文件名 @echo 14 - 层级子目录:前缀字符-文件名 @echo -----------------2 .加后缀----------------- @echo 21 - 当前目录:文件名-目录名 @echo 22 - 层级子目录:文件名-子目录名 @echo 23 - 当前目录:文件名-后缀字符 @echo 24 - 层级子目录:文件名-后缀字符 @echo -----------------3 .加序数----------------- @echo 31 - 当前目录:序数 @echo 32 - 层级子目录:序数 @echo 33 - 当前目录:文件名-序数 @echo 34 - 层级子目录:文件名-序数 @echo 35 - 当前目录:目录名-序数 @echo 36 - 层级子目录:子目录名-序数 @echo 37 - 当前目录:字符-序数 @echo -------------31 .加序数(零占位)------------- @echo 311 - 当前目录:目录名-两位序数 @echo 312 - 层级子目录:子目录名-两位序数 @echo 313 - 当前目录:字符-两位序数 @echo 314 - 当前目录:目录名-三位序数 @echo 315 - 层级子目录:子目录名-三位序数 @echo 316 - 当前目录:字符-三位序数 @echo ----------------4 .替换删除---------------- @echo 41 - 替换当前目录下文件名 @echo 42 - 替换所有子层级中的文件名 @echo 43 - 删除当前目录下文件名 @echo 44 - 删除所有子层级中的文件名 @echo -------------------其它------------------- @echo 8 - 重新选择目录 @echo 9 - 退出 @echo . set GTOperator=9 set /p GTOperator="选择操作数后: "@echo . if %GTOperator% equ 11 goto GTDIRPREFIXif %GTOperator% equ 12 goto GTSUBDIRPREFIXif %GTOperator% equ 13 goto GTDIRPREFIXCUSTOMif %GTOperator% equ 14 goto GTSUBDIRPREFIXCUSTOMif %GTOperator% equ 21 goto GTDIRSUFFIXif %GTOperator% equ 22 goto GTSUBDIRSUFFIXif %GTOperator% equ 23 goto GTDIRSUFFIXCUSTOMif %GTOperator% equ 24 goto GTSUBDIRSUFFIXCUSTOMif %GTOperator% equ 31 goto GTDIRORDINALif %GTOperator% equ 32 goto GTSUBDIRORDINALif %GTOperator% equ 33 goto GTDIRFLIENAMEORDINALif %GTOperator% equ 34 goto GTSUBDIRFILENAMEORDINALif %GTOperator% equ 35 goto GTDIRNAMEORDINALif %GTOperator% equ 36 goto GTSUBDIRNAMEORDINALif %GTOperator% equ 37 goto GTDIRCUSTOMNAMEORDINALif %GTOperator% equ 311 goto GTDIRNAMEORDINALOOif %GTOperator% equ 312 goto GTSUBDIRNAMEORDINALOOif %GTOperator% equ 313 goto GTDIRCUSTOMNAMEORDINALOOif %GTOperator% equ 314 goto GTDIRNAMEORDINALOOOif %GTOperator% equ 315 goto GTSUBDIRNAMEORDINALOOOif %GTOperator% equ 316 goto GTDIRCUSTOMNAMEORDINALOOOif %GTOperator% equ 41 goto GTDIRREPLACEif %GTOperator% equ 42 goto GTSUBDIRREPLACEif %GTOperator% equ 43 goto GTDIRDELif %GTOperator% equ 44 goto GTSUBDIRDELif %GTOperator% equ 8 goto GTBeginif %GTOperator% equ 9 goto GTExitecho 请选择正确的操作数pause >nul goto GTCONTINUE:GTDIRPREFIX cd /d "!HandleDir! "for /f "delims=" %%i in ("%cd% ") do set "DirNamePrefix=%%~ nxi"for /f "delims=" %%i in ('dir /a-d /b *.* 2 ^>nul ') do ( if not "%~nx0"=="% %i" ( ren "%%i " "%DirNamePrefix% -%%~ nxi" ) ) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRPREFIX cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( for /f "usebackq delims=" %%j in (`dir /a-d /b "%%i \*.*" 2 ^>nul `) do ( ren "%%i \%%j " "%%~ nxi-%%~ nxj" ) ) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRPREFIXCUSTOM set FilePrefix=""set /p FilePrefix="前缀字符:"cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /a-d/b`) do (if not "%%i "==%0 ren "%%i " "%FilePrefix% %%~ nxi")echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRPREFIXCUSTOM set SubFilePrefix=""set /p SubFilePrefix="前缀字符:"cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( for /f "usebackq delims=" %%j in (`dir /a-d /b "%%i \*.*" 2 ^>nul `) do ( ren "%%i \%%j " "!SubFilePrefix! %%~ nxj")) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRSUFFIX cd /d "!HandleDir! "for /f "delims=" %%i in ("%cd% ") do set "DirNameSuffix=%%~ nxi"for /f "delims=" %%i in ('dir /a-d /b *.* 2 ^>nul ') do ( if not "%~nx0"=="% %i" ( ren "%%i " "%%~ ni-%DirNameSuffix% %%~ xi" ) ) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRSUFFIX cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( for /f "usebackq delims=" %%j in (`dir /a-d /b "%%i \*.*" 2 ^>nul `) do ( ren "%%i \%%j " "%%~ nj-%%~ nxi%%~ xj" ) ) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRSUFFIXCUSTOM set FileSuffix=""set /p FileSuffix="后缀字符:"cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /a-d/b`) do (if not "%%i "==%0 ren "%%i " "%%~ ni!FileSuffix! %%~ xi")echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRSUFFIXCUSTOM set SubFileSuffix=""set /p SubFileSuffix="后缀字符:"cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( for /f "usebackq delims=" %%j in (`dir /a-d /b "%%i \*.*" 2 ^>nul `) do ( ren "%%i \%%j " "%%~ nj!SubFileSuffix! %%~ xj")) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRORDINAL set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRORDINALORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRORDINALORDERBY)cd /d "!HandleDir! "set /a num=0 for /f "usebackq tokens=*" %%i in (`dir /a-d /b /o!OrderBy! /tc`) do ( if not "%%i "=="%~n0% ~x0" ( set /a num+=1 ren "%%i " "!num! %%~ xi" )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRORDINAL set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTSUBDIRORDINALORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTSUBDIRORDINALORDERBY)cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( set /a num=0 for /f "usebackq delims=" %%j in (`dir /a-d /b /o!OrderBy! "%%i \*.*" 2 ^>nul `) do ( set /a num+=1 ren "%%i \%%j " "!num! %%~ xj" )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRFLIENAMEORDINAL set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRFLIENAMEORDINALORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRFLIENAMEORDINALORDERBY)cd /d "!HandleDir! "set /a num=0 for /f "usebackq delims=" %%i in (`dir /a-d /b /o!OrderBy! *.* 2 ^>nul `) do ( if not "%~nx0"=="% %i" ( set /a num+=1 ren "%%i " "%%~ ni-!num! %%~ xi")) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRFILENAMEORDINAL set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTSUBDIRFILENAMEORDINALORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTSUBDIRFILENAMEORDINALORDERBY)cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( set /a num=0 for /f "usebackq delims=" %%j in (`dir /a-d /b /o!OrderBy! "%%i \*.*" 2 ^>nul `) do ( set /a num+=1 ren "%%i \%%j " "%%~ nj-!num! %%~ xj" )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRNAMEORDINAL set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRNAMEORDINALORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRNAMEORDINALORDERBY)cd /d "!HandleDir! "set /a num=0 for /f "usebackq delims=" %%i in ('%cd% ') do set "DirNamePrefix=%%~ nxi"for /f "usebackq delims=" %%i in (`dir /a-d /b /o!OrderBy! *.* 2 ^>nul `) do ( if not "%~nx0"=="% %i" ( set /a num+=1 ren "%%i " "%DirNamePrefix% -!num! %%~ xi")) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRNAMEORDINAL cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( set /a num=0 for /f "usebackq delims=" %%j in (`dir /a-d /b /o!OrderBy! "%%i \*.*" 2 ^>nul `) do ( set /a num+=1 ren "%%i \%%j " "%%~ nxi-!num! %%~ xj" )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRCUSTOMNAMEORDINAL set SubFilePrefix=""set StartNum=0 set /p SubFilePrefix="前缀字符:"set /p StartNum="开始序数:"set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTORDERBY)cd /d "!HandleDir! "for /f "usebackq tokens=*" %%i in (`dir /a-d /b /o!OrderBy! `) do ( if not "%%i "=="%~n0% ~x0" ( set /a StartNum+=1 ren "%%i " "!SubFilePrefix! !StartNum! %%~ xi" )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRNAMEORDINALOO set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRNAMEORDINALOOORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRNAMEORDINALOOORDERBY)cd /d "!HandleDir! "set /a num=0 for /f "usebackq delims=" %%i in ('%cd% ') do set "DirNamePrefix=%%~ nxi"for /f "usebackq delims=" %%i in (`dir /a-d /b /o!OrderBy! *.* 2 ^>nul `) do ( if not "%~nx0"=="% %i" ( set /a num+=1 if !num! LSS 10 ( ren "%%i " "%DirNamePrefix% -0 !num! %%~ xi" ) else ( ren "%%i " "%DirNamePrefix% -!num! %%~ xi" ) )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRNAMEORDINALOO set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTSUBDIRNAMEORDINALOOORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTSUBDIRNAMEORDINALOOORDERBY)cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( set /a num=0 for /f "usebackq delims=" %%j in (`dir /a-d /b /o!OrderBy! "%%i \*.*" 2 ^>nul `) do ( set /a num+=1 if !num! LSS 10 ( ren "%%i \%%j " "%%~ ni-0 !num! %%~ xj" ) else ( ren "%%i \%%j " "%%~ ni-!num! %%~ xj" ) )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRCUSTOMNAMEORDINALOO set SubFilePrefix=""set StartNum=0 set /p SubFilePrefix="前缀字符:"set /p StartNum="开始序数:"set /a StartNum-=1 set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRCUSTOMNAMEORDINALOOORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRCUSTOMNAMEORDINALOOORDERBY)cd /d "!HandleDir! "for /f "usebackq tokens=*" %%i in (`dir /a-d /b /o!OrderBy! `) do ( if not "%%i "=="%~n0% ~x0" ( set /a StartNum+=1 if !StartNum! LSS 10 ( ren "%%i " "!SubFilePrefix! 0 !StartNum! %%~ xi" ) else ( ren "%%i " "!SubFilePrefix! !StartNum! %%~ xi" ) )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRNAMEORDINALOOO set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRNAMEORDINALOOOORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRNAMEORDINALOOOORDERBY)cd /d "!HandleDir! "set /a num=0 for /f "usebackq delims=" %%i in ('%cd% ') do set "DirNamePrefix=%%~ nxi"for /f "usebackq delims=" %%i in (`dir /a-d /b /o!OrderBy! *.* 2 ^>nul `) do ( if not "%~nx0"=="% %i" ( set /a num+=1 if !num! LSS 10 ( ren "%%i " "%DirNamePrefix% -00 !num! %%~ xi" ) else ( if !num! LSS 100 ( ren "%%i " "%DirNamePrefix% -0 !num! %%~ xi" ) else ( ren "%%i " "%DirNamePrefix% -!num! %%~ xi" ) ) )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRNAMEORDINALOOO set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTSUBDIRNAMEORDINALOOOORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTSUBDIRNAMEORDINALOOOORDERBY)cd /d "!HandleDir! "for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( set /a num=0 for /f "usebackq delims=" %%j in (`dir /a-d /b /o!OrderBy! "%%i \*.*" 2 ^>nul `) do ( set /a num+=1 if !num! LSS 10 ( ren "%%i \%%j " "%%~ nxi-00 !num! %%~ xj" ) else ( if !num! LSS 100 ( ren "%%i \%%j " "%%~ nxi-0 !num! %%~ xj" ) else ( ren "%%i \%%j " "%%~ nxi-!num! %%~ xj" ) ) )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRCUSTOMNAMEORDINALOOO set SubFilePrefix=""set StartNum=0 set /p SubFilePrefix="前缀字符:"set /p StartNum="开始序数:"set /a StartNum-=1 set NOrderBy=1 @echo . @echo 文件排序方式 @echo -------------------------------------------- @echo 1 .文件大小 @echo 2 .文件小大 @echo 3 .创建时间早晚 @echo 4 .创建时间晚早 @echo 5 .文件名A-Z @echo 6 .文件名Z-A @echo 7 .扩展名A-Z @echo 8 .扩展名Z-A @echo -------------------------------------------- :GTDIRCUSTOMNAMEORDINALOOOORDERBY set /p NOrderBy="文件排序方式:"set OrderBy=dif %NOrderBy% equ 1 (set OrderBy=-s)if %NOrderBy% equ 2 (set OrderBy=s)if %NOrderBy% equ 3 (set OrderBy=d)if %NOrderBy% equ 4 (set OrderBy=-d)if %NOrderBy% equ 5 (set OrderBy=n)if %NOrderBy% equ 6 (set OrderBy=-n)if %NOrderBy% equ 7 (set OrderBy=-e)if %NOrderBy% equ 8 (set OrderBy=e)echo %NOrderBy% |findstr /be "[1 -8 ]" >nul || (echo 选择支持的排序方式 & goto GTDIRCUSTOMNAMEORDINALOOOORDERBY)cd /d "!HandleDir! "for /f "usebackq tokens=*" %%i in (`dir /a-d /b /o!OrderBy! `) do ( if not "%%i "=="%~n0% ~x0" ( set /a StartNum+=1 if !StartNum! LSS 10 ( ren "%%i " "!SubFilePrefix! 00 !StartNum! %%~ xi" ) else ( if !StartNum! LSS 100 ( ren "%%i " "!SubFilePrefix! 0 !StartNum! %%~ xi" ) else ( ren "%%i " "!SubFilePrefix! !StartNum! %%~ xi" ) ) )) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRREPLACE cd /d "!HandleDir! "set /p oldStr=原字符:set /p newStr=替换成:for /f "usebackq tokens=*" %%a in (`dir /a-d /b`) do ( set "newFileName=%%~ na" set "newFileName=!newFileName:%oldStr%=%newStr%! " ren "%%a " "!newFileName! %%~ xa" ) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRREPLACE cd /d "!HandleDir! "set /p oldStr=原字符:set /p newStr=替换成:for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( for /f "usebackq delims=" %%j in (`dir /a-d /b "%%i \" 2 ^>nul `) do ( set "newFileName=%%~ nj" set "newFileName=!newFileName:%oldStr%=%newStr%! " ren "%%i \%%j " "!newFileName! %%~ xj")) set oldStr=""set newStr=""set newFileName=""echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTDIRDEL cd /d "!HandleDir! "set /p DelStr=删除字符:for /f "usebackq tokens=*" %%a in (`dir /a-d /b`) do ( set "str=%%~ na" set "str=!str:%DelStr%=! " ren "%%a " "!str! %%~ xa" ) echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTSUBDIRDEL cd /d "!HandleDir! "set /p DelStr=删除字符:for /f "usebackq delims=" %%i in (`dir /ad /b /s^|sort /r`) do ( for /f "usebackq delims=" %%j in (`dir /a-d /b "%%i \" 2 ^>nul `) do ( set "str=%%~ nj" set "str=!str:%DelStr%=! " ren "%%i \%%j " "!str! %%~ xj")) set DelStr=""set str=""echo .echo :) 搞定(回车继续其它操作)pause >nul goto GTCONTINUE:GTExit exit
(本篇结束)