Windows 有一種簡單的方法,只需要選取需要的檔案,於第一個檔案重新命名,輸入指定的文字
就會將選取需要的檔案順次序改名,但這種改名方法的結果就不太理想
當然 Windows 上還有其他批次重新命名軟件
Linux 上亦有一種稱為 rename 的指令,一次過將大量檔案重新命名
但要讓檔案順著某個編號開始排列,rename 又好像不太適合
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 | #!/bin/sh run(){ destination= "${1}" source = "${2}" suf= "${3}" pre= "${4}" len= "${5}" start= "${6}" if ! [ -d "${source}" ]; then echo "<source> '${source}' is not an exist directory" elif ! [ -d "${destination}" ]; then echo "<destination> '${destination}' is not an exist directory" else if [ "${#len}" - eq 0 ]; then len=1 fi if [ "${#start}" - eq 0 ]; then start=1 fi i=0 for f in "${source}/" *; do if [ -f "${f}" ]; then i=$((i+1)) fi done count= "${i}" length= "${#count}" if [ "${len}" -gt "${length}" ]; then length= "${len}" fi i= "${start}" if [ "${i}" -lt 1 ]; then i=1 fi for f in "${source}/" *; do if [ -f "${f}" ]; then no= "${i}" while [ "${#no}" -lt "${length}" ]; do no= "0${no}" done echo "cp '${f}' '${destination}/${pre}${no}${suf}'" cp "${f}" "${destination}/${pre}${no}${suf}" i=$((i+1)) fi done fi } if [ "${#}" - eq 1 ]; then destination= "${1}" source = '.' suf= '' pre= '' length=0 start=1 can_run=1 elif [ "${#}" - eq 2 ]; then destination= "${1}" source = "${2}" suf= '' pre= '' length=0 start=1 can_run=1 elif [ "${#}" - eq 3 ]; then destination= "${1}" source = "${2}" suf= "${3}" pre= '' length=0 start=1 can_run=1 elif [ "${#}" - eq 4 ]; then destination= "${1}" source = "${2}" suf= "${3}" pre= "${4}" length=0 start=1 can_run=1 elif [ "${#}" - eq 5 ]; then destination= "${1}" source = "${2}" suf= "${3}" pre= "${4}" length= "${5}" start=1 can_run=1 elif [ "${#}" - eq 6 ]; then destination= "${1}" source = "${2}" suf= "${3}" pre= "${4}" length= "${5}" start= "${6}" can_run=1 else echo "${0} <destination> [source=. [suffix= [prefix= [length= [start=1]]]]]" can_run=0 fi if [ "${can_run}" - eq 1 ]; then run "${destination}" "${source}" "${suf}" "${pre}" "${length}" "${start}" fi # |
script 中最後的 # 是不需要的
使用方法相當簡單
script 只需要任意名稱、如 a.out
利用
1 | . /a .out <destination> [ source =. [suffix= [prefix= [length= [start=1]]]]] |
source 可選,為輸入目錄;若不設定,則使用當前目錄
suffix 可選,為輸出檔案名的後綴;若不設定,為空字串
prefix 可選,為輸出檔案名的前綴;若不設定,為空字串
length 可選,為自動編號的長度;若不設定,則使用批次量的數值長度
start 可選,為自動編號的起首數值,若不設定,則為 1
例如
1 | . /a .out ~ /comic ~ /Downloads .jpg file - 3 1 |
沒有留言 :
張貼留言