整理手機SD卡的時候發現了這個……以前的自己真偉大……
為Android撰寫。原則上可以在任何Linux內核的系統上運行。
如果要在Android上運行,你需要一個bash like shell,比如bash,mksh,一個支持中文的busybox。
點擊這裡下載binary,並把它們放到/system/xbin下,建立必要的鏈接,增加執行許可權
這裡是腳本:br.sh ,放到你喜歡的地方,添加執行許可權
差不多這個樣子:
順便貼上:
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 |
#This script only work in bash or bash like shell #!/system/xbin/bash #change to /sbin/bash if Linux #Option list OPTS="Replace Cut Add Shell Help Config Exit" PRESUF="Prefix Suffix" STRNUM="String Number" CONFIG="Default.." #Acutually CONFIG will be overwrite #Consts NAME="33[1mBatch Rename33[22m" VERSION="33[1m1.0433[22m" BUILD="33[1m2012.6 533[22m" COPYRIGHT="\n33[1mCopyright (C) 2012, fffonion.33[22mHaven't been licenced under GPLv2 or other yet.\nT^T\n" IS_WINDOWS=false #Configuration vars PS3="Select> " #error codes #1:bash or busybox not found br_nprint() { echo -n -e "33[36m"$@"33[0m" } br_errprt() { #if [ ! $@"." = "." ];then echo -e "33[31m"$@"33[0m" >&2 #fi } br_normalprt() { #echo -e "33[37m"$@"33[0m" echo -e "33[0m"$@"33[0m" } br_helpprt() { echo -e "33[32m"$@"33[0m" } br_promptprt() { echo -e "33[4m"$@"33[24m" } br_flush() { BRDIR_BF="" COUNT=0 PATTERN="" SUFFIX="" PREFIX="" REPLACE="" FILENAME="" NUM_START=0 NUM_STEP=1 #DESC=0 USINGNUM=0 file="" DONOTHING=false DEPTH="|" #to draw a tree } br_flushconfig() { RECURSE=false MATCH_ALL=true SHOWPROGRESS=true TESTMODE=false } br_help() { br_helpprt "$NAME by Onion v$VERSION build $BUILD\n$COPYRIGHT\n" br_helpprt "Usage: br PATH -rca[taRu] [arguments]...\n" br_helpprt "$NAME is a bash script to help you manage filenames more efficiently.\n" br_helpprt "Enter (like) $0 without arguments for a text UI." br_helpprt "\t--help\tThis help." br_helpprt "\t--version-t\tPrint version." br_helpprt "\t-r PATTERN REPLACE\n\t\tReplace pattern string with replace string." br_helpprt "\t-a PREFIX SUFFIX\n\t\tAdd prefix and suffix." br_helpprt "\t-c PATTERN\n\t\tRemove pattern string." br_helpprt "\t-u\tUse saved config(if exist)." br_helpprt "\t-a\tMatch all patterns." br_helpprt "\t-s\tSilent mode.Do not show progress." br_helpprt "\t-R\tRecurse." br_helpprt "\t-t\tTest mode(don't take effect)." } br_helpUI() { local p br_helpprt "\n$NAME is a bash script to help you manage filename more efficiently.\n" br_helpprt "Follow the menu and input the number of your choice.\n" br_helpprt "Use Shell for a quick access to interpreter.\n" br_helpprt "Tips:When entering path for the second time, press enter to use last specified path" br_nprint "More?(y/n)" read p if [ $p"." = "y." ] || [ $p"." = "." ];then br_helpprt "33[1m[Useful Information]33[22m" br_helpprt "33[1mWhereis Script:33[22m $0\n33[1mConfig file:33[22m $SAVEPATH\n33[1mCurrent path: 33[22m$BRDIR\t33[1mRoot user:33[22m $ROOTED\n33[1mBINARY:33[22m $BINARY" fi } br_checksupport() { if [ -e /system/bin/busybox ];then BINARY="/system/bin/busybox " #Debug only elif [ -e /system/xbin/busybox ];then BINARY="/system/xbin/busybox " elif ! ls >/dev/null 2>&1;then br_errprt "Basic shell binary not found.\nYou may install them first." br_normalprt "Or enter a 33[1mbusybox33[22m path below." BINARY="|" while ! $BINARY >/dev/null 2>&1;do if ! [ "$BINARY." = "|." ];then br_errprt "33[1m$BINARY33[22m not found or permission denied." fi br_nprint "Busybox(esc for escape):" read BINARY if [ "$BINARY." = "esc." ] || [ "$BINARY." = "." ];then br_helpprt Canceled. exit 1 fi done elif ! bash --version >/dev/null 2>&1;then br_errprt Bash not found. exit 1 else BINARY="" fi BR_LS=$BINARY"ls" BR_CAT=$BINARY"cat" BR_MV=$BINARY"mv" BR_BASENAME=$BINARY"basename" } br_checkpath() { if $BR_LS /data/data > /dev/null 2>&1;then #someone may say -e ..su is better, but concerning rooted users running unroot terminal. ROOTED=true else ROOTED=false fi if [ -d /mnt/asec/ ] && $ROOTED;then #is android SAVEPATH="/data/.br_config" elif [ -d /mnt/asec/ ] && ! $ROOTED;then SAVEPATH="/sdcard/.br_config" elif [ -d "c:\\" ];then #in windows SAVEPATH=c:\\.br_config IS_WINDOWS=true BR_MV="move" else #common linux USERNAME=`id |cut -f 1 -d ' '|sed 's/.\+(//'|sed 's/)//'` SAVEPATH="/home/$USERNAME/.br_config" fi } br_setconfig() { br_checkpath echo "$SHOWPROGRESS $RECURSE $MATCH_ALL $TESTMODE $BRDIR $BINARY" > $SAVEPATH } br_getconfig() { br_checkpath if ! $BR_CAT $SAVEPATH > /dev/null 2>&1;then #first run br_checksupport br_flushconfig else read SHOWPROGRESS RECURSE MATCH_ALL TESTMODE BRDIR BINARY < $SAVEPATH #echo $SHOWPROGRESS $RECURSE $MATCH_ALL $BRDIR fi } br_initcfg() { #Init CONFIG opts if $SHOWPROGRESS;then CONFIG="Progress:On" else CONFIG="Progress:Off" fi if $RECURSE;then CONFIG=$CONFIG" Recurse:On" else CONFIG=$CONFIG" Recurse:Off" fi if $MATCH_ALL;then CONFIG=$CONFIG" Match:All" else CONFIG=$CONFIG" Match:Once" fi if $TESTMODE;then CONFIG=$CONFIG" Test:On" else CONFIG=$CONFIG" Test:Off" fi CONFIG=$CONFIG" Default.." } br_config() { br_promptprt "33[1m[Setup Menu]33[22m" br_initcfg select opt in $CONFIG;do if [ $opt"." = "Progress:Off." ];then SHOWPROGRESS=true br_normalprt I will show you the progree. elif [ $opt"." = "Progress:On." ];then SHOWPROGRESS=false br_normalprt I will no longer show progress. elif [ $opt"." = "Recurse:Off." ];then RECURSE=true br_normalprt I will now recurse into folders. elif [ $opt"." = "Recurse:On." ];then RECURSE=false br_normalprt I will not recurse into folders. elif [ $opt"." = "Match:Onc." ];then MATCH_ALL=true br_normalprt I will match all the patterns. elif [ $opt"." = "Match:All." ];then MATCH_ALL=false br_normalprt I will only match the first pattern. elif [ $opt"." = "Test:On." ];then TESTMODE=false br_normalprt Renaming will take effect. elif [ $opt"." = "Test:Off." ];then TESTMODE=true br_normalprt Renaming will only be showed as preview. elif [ $opt"." = "Default..." ];then br_flushconfig br_helpprt "Custom setting cleaned." rm $SAVEPATH >/dev/null 2>&1 #elif [ $opt"." = "." ];then #br_helpprt "Show progress? $PROGRESS\tRecurse? $RECURSE\nReplace all? $MATCH_ALL" else br_errprt "Bad choice." continue fi break done } br_setdir() { local p br_nprint "Specify the path(Enter for last path)": BRDIR_BF=$BRDIR read BRDIR if [ $BRDIR"." = "." ];then BRDIR=$BRDIR_BF fi if $IS_WINDOWS;then BRDIR_TMP=${BRDIR//:\//:} BRDIR_TMP=${BRDIR_TMP//:\\/:} else BRDIR_TMP=$BRDIR fi if ! ls $BRDIR_TMP >/dev/null 2>&1;then br_errprt "$BRDIR not exist." br_nprint "Continue?(y/n):" read p if ! ( [ $p"." = "." ] || [ $p"." = "y." ] );then br_setdir fi fi } br_do() { local COUNT_BF=$COUNT COUNT=0 local DEPTH_BF=$DEPTH DEPTH=$DEPTH"-" echo $1 #if [ $1"." = "." ] || ! $BR_CD $1 >/dev/null 2>&1;then # br_errprt "Error parsing path, exiting action..." # DONOTHING=true #fi local FILENAME_AFTER="" if ! $DONOTHING;then br_helpprt $DEPTH"Now listing files in $1 ..." fi for file in `$BR_LS -Ad "$1"/* 2>/dev/null |sed 's/ /-THIS_IS_SPACE-/g'`; do file=`echo $file|sed 's/-THIS_IS_SPACE-/ /g'` if $IS_WINDOWS;then file=${file//\\/\/} file=${file//:/:\/} fi #echo $file if $DONOTHING;then break fi local FILENAME=$($BR_BASENAME "$file") if $MATCH_ALL;then FILENAME_AFTER=${FILENAME//$PATTERN/$REPLACE} else FILENAME_AFTER=${FILENAME/$PATTERN/$REPLACE} fi #echo ${file/$PATTERN/$REPLACE} if [ -d "$file" ] && $RECURSE;then br_do "$file" else if ! ( [ "$PATTERN$REPLACE." = "." ] || ! [ -e "$FILENAME_AFTER" ]);then #means: #|NO INPUT| MATCH || GO? | #| T | T || T | #| F | F || T | #| F | T || F | #| T | F |Impossible| #A simple !XOR can handle this, but not found in bash script... continue else let "COUNT=$COUNT+1" if [ $USINGNUM = 1 ];then let "PREFIX= $NUM_START+($COUNT-1)*$NUM_STEP" elif [ $USINGNUM = 2 ];then let "SUFFIX= $NUM_START+($COUNT-1)*$NUM_STEP" fi #-1 is offset for . and .. FILENAME_AFTER="$PREFIX$FILENAME_AFTER$SUFFIX" #echo $FILENAME_AFTER if ! $TESTMODE;then $BR_MV "$file" "$FILENAME_AFTER" #>/dev/null 2>&1 PRMPT_1="Renaming" PRMPT_2="" else PRMPT_1="Will rename" PRMPT_2=" will be" fi if $SHOWPROGRESS;then br_normalprt "33[33m"$DEPTH"$PRMPT_1 : $($BR_BASENAME "$file") > $($BR_BASENAME "$FILENAME_AFTER")" fi fi fi done br_normalprt "33[33;1m$DEPTH$COUNT file(s)$PRMPT_2 renamed in folder $133[22m" COUNT=$COUNT_BF DEPTH=$DEPTH_BF #go back to father folder $BR_CD .. } br_cut() { br_setdir br_nprint "Pattern:" read PATTERN br_do $BRDIR } br_add() { br_setdir local INPUT br_promptprt "Choose what you want to add:" select opt1 in $STRNUM;do if [ $opt1"." = "String." ];then br_nprint Enter string: read INPUT USINGNUM=0 elif [ $opt1"." = "Number." ];then br_nprint Start from: read NUM_START br_nprint Step: read NUM_STEP USINGNUM=1 #init usingnum else br_errprt "Bad choice." continue fi break #only run once done #number situation escaped br_promptprt "Add string as what:" select opt2 in $PRESUF;do if [ $opt2"." = "Prefix." ];then PREFIX=$INPUT #let "USINGNUM*=1" break elif [ $opt2"." = "Suffix." ];then SUFFIX=$INPUT let "USINGNUM=$USINGNUM*2" break else br_errprt "Bad choice." fi done br_do $BRDIR } br_rp() { br_setdir br_nprint "Pattern:" read PATTERN br_nprint "Replace 33[1m$PATTERN33[22m with:" read REPLACE br_do $BRDIR } br_cmd() { INPUT="none" br_promptprt "Command mode. Input e for quit, h for help." while [ ! $INPUT"." = "e." ];do br_nprint "BR$VERSION>" read INPUT if [ $INPUT"." = "h." ];then br_help elif [ ! $INPUT"." = "e." ];then $INPUT fi done } br_classic() { if [ $1 = "--help" ];then br_help exit elif [ $1 = "--version" ];then br_normalprt $NAME $VERSION exit fi ARG="$2" if ! [ "$ARG." = "${ARG/u/}." ];then ARG="${ARG//u/}" #use saved config else br_flushconfig if ! [ "$ARG." = "${ARG/R/}." ];then RECURSE=true fi if ! [ "$ARG." = "${ARG/s/}." ];then SHOWPROGRESS=false fi if [ "$ARG." = "${ARG/a/}." ];then MATCH_ALL=false fi if ! [ "$ARG." = "${ARG/t/}." ];then TESTMODE=true fi fi ARG="${ARG//a/}" ARG="${ARG//t/}" ARG="${ARG//R/}" ARG="${ARG//s/}" if [ "$ARG" = "-r" ];then PATTERN=$3 REPLACE=$4 BRDIR=$1 elif [ "$ARG" = "-c" ];then PATTERN=$3 BRDIR=$1 elif [ "ARG" = "-a" ];then BRDIR=$1 PREFIX=$3 SUFFIX=$4 elif [ "$ARG." != "-." ] && [ "$ARG." != "." ];then br_errprt "Error parsing arguments: '$ARG' .\nUse --help to see help." exit 2 fi #echo 1$SHOWPROGRESS 2$MATCH_ALL 3$RECURSE 4$TESTMODE br_do $BRDIR } #Main Entry br_getconfig #will judge whether first run if [ $1"." = "." ];then br_helpprt "$NAME by Onion v$VERSION build $BUILD\n$COPYRIGHT" br_promptprt "What do you want to do:" select opt in $OPTS;do br_flush if [ $opt"." = "Replace." ];then br_rp elif [ $opt"." = "Cut." ];then br_cut elif [ $opt"." = "Add." ]; then br_add elif [ $opt"." = "Shell." ]; then br_cmd elif [ $opt"." = "Help." ];then br_helpUI elif [ $opt"." = "Config." ];then br_config elif [ $opt"." = "Exit." ];then br_normalprt "$NAME v$VERSION exit successfully" br_setconfig exit 0 else br_errprt "Bad choice." fi br_normalprt "33[1m[Main menu selection]:33[22m" #show prompt at not first time done; else br_classic $@ fi exit 0 |