怎麼樣突破這個伸到功能,您可以在每個呼叫類型:
rename_files() {
title="${1##*${2} - }"
for filename in "$1/"*.*; do
case "${filename##*.}" in
mkv|avi|mp4)
new_path="Downloaded/${2}/${title}-$(basename "$filename")"
echo "moving $filename -> $new_path"
mv "$filename" "$new_path"
;;
esac
done
}
rename_category() {
for path in "Downloads/${1}"*; do
rename_files "$path" "$1"
done
}
然後,只需調用它需要:
rename_category SERIES
rename_category MOVIES
例如,我開始使用此:
.
├── Downloaded
│ ├── MOVIES
│ └── SERIES
├── Downloads
│ ├── MOVIES\ -\ bar
│ │ ├── bar.mp4
│ │ └── foo.mp4
│ ├── MOVIES\ -\ foo
│ │ ├── bar.mp4
│ │ └── foo.mp4
│ ├── SERIES\ -\ bar
│ │ ├── bar.mp4
│ │ └── foo.mp4
│ └── SERIES\ -\ foo
│ ├── bar.mp4
│ └── foo.mp4
├── after.txt
├── before.txt
└── rename_script.sh
8 directories, 11 files
之後running the script我得到了:
moving Downloads/SERIES - bar/bar.mp4 -> Downloaded/SERIES/bar-bar.mp4
moving Downloads/SERIES - bar/foo.mp4 -> Downloaded/SERIES/bar-foo.mp4
moving Downloads/SERIES - foo/bar.mp4 -> Downloaded/SERIES/foo-bar.mp4
moving Downloads/SERIES - foo/foo.mp4 -> Downloaded/SERIES/foo-foo.mp4
moving Downloads/MOVIES - bar/bar.mp4 -> Downloaded/MOVIES/bar-bar.mp4
moving Downloads/MOVIES - bar/foo.mp4 -> Downloaded/MOVIES/bar-foo.mp4
moving Downloads/MOVIES - foo/bar.mp4 -> Downloaded/MOVIES/foo-bar.mp4
moving Downloads/MOVIES - foo/foo.mp4 -> Downloaded/MOVIES/foo-foo.mp4
.
├── Downloaded
│ ├── MOVIES
│ │ ├── bar-bar.mp4
│ │ ├── bar-foo.mp4
│ │ ├── foo-bar.mp4
│ │ └── foo-foo.mp4
│ └── SERIES
│ ├── bar-bar.mp4
│ ├── bar-foo.mp4
│ ├── foo-bar.mp4
│ └── foo-foo.mp4
├── Downloads
│ ├── MOVIES\ -\ bar
│ ├── MOVIES\ -\ foo
│ ├── SERIES\ -\ bar
│ └── SERIES\ -\ foo
├── after.txt
├── before.txt
└── rename_script.sh
8 directories, 11 files
編輯:OP必須從…/SERIES - BlahBlah/blah.ext
到…/SERIES/BlahBlah-blah.ext
我相信會的興趣。
您可能想使用'awk'來處理文件名 –
可以給我一個例子嗎? – DylanDog
'renamedpath = $(echo $ filename | awk' ...')' –