name : add name_postfix.
This commit is contained in:
parent
a6438e0e5f
commit
c3301caa23
|
@ -557,7 +557,8 @@ Command|Description
|
|||
`name_series <SEASON> [FILES]`|Rename files to Jellyfin's show format: `Episode S01E01.mkv`.
|
||||
`name_manga <SEASON> [FILES]`|Rename files to Kavita's manga format: `Name Vol.1 Ch.01.cbr`.
|
||||
`name_ext <EXTENSION> [FILES]`|Change file extensions.
|
||||
`name_prefix [OLD] [NEW] [FILES]`|Change file prefix.
|
||||
`name_prefix <OLD> <NEW> [FILES]`|Change file prefix.
|
||||
`name_postfix <OLD> <NEW> [FILES]`|Change file postfix.
|
||||
|
||||
## Ncdu.
|
||||
|
||||
|
|
|
@ -331,8 +331,8 @@ name_ext()
|
|||
fi
|
||||
}
|
||||
|
||||
# Change file's prefixes.
|
||||
# Usage: name_prefix [OLD] [NEW] [FILES]
|
||||
# Change file prefixes.
|
||||
# Usage: name_prefix <OLD> <NEW> [FILES]
|
||||
name_prefix()
|
||||
{
|
||||
local IFS=$'\n'
|
||||
|
@ -379,5 +379,53 @@ name_prefix()
|
|||
fi
|
||||
}
|
||||
|
||||
# Change file postfix.
|
||||
# Usage: name_postfix <OLD> <NEW> [FILES]
|
||||
name_postfix()
|
||||
{
|
||||
local IFS=$'\n'
|
||||
local old="${1}" # Old postfix.
|
||||
local new="${2}" # New postfix.
|
||||
local targets=("${@:3}") # Target files.
|
||||
local count=0 # Total files processed.
|
||||
local total=$((${#}-2)) # Total files to process.
|
||||
local failed=0
|
||||
|
||||
# All targets by default.
|
||||
if [[ "${targets}" = "" ]]; then
|
||||
targets=([^.]*)
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
# Process.
|
||||
for target in "${targets[@]}"; do
|
||||
# Increment counter.
|
||||
((count++))
|
||||
|
||||
# Create new name.
|
||||
local new_name="${new}${target%$old}"
|
||||
|
||||
# Prepare status.
|
||||
local status="[${count}/${total}] ${target} -> ${new_name}"
|
||||
echo -e "${status}"
|
||||
|
||||
# Warning on no change.
|
||||
[[ "${target}" = "${new_name}" ]] && continue
|
||||
|
||||
# Rename.
|
||||
mv -- "${target}" "${new_name}"
|
||||
|
||||
if [[ ${?} != 0 ]]; then
|
||||
echo -e "${color_bred}${status}: Failed.${color_default}"
|
||||
((failed++))
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${failed} != 0 ]]; then
|
||||
echo -e "${color_bred}Failed: ${failed}.${color_default}"
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
# export for parallel.
|
||||
export -f name name_hash name_hash_check name_ext
|
||||
|
|
Reference in a new issue