Ensure the video ID appears at the end of the filename inside square brackets.
This commit is contained in:
parent
700f36c2c5
commit
af5ebf21f1
28
move-[id]-to-end.bash
Normal file
28
move-[id]-to-end.bash
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
for f in *; do
|
||||
# Skip directories
|
||||
[ -f "$f" ] || continue
|
||||
|
||||
# Extract the ID inside () or []
|
||||
id=$(echo "$f" | sed -n 's/.*[([]\([^])]*\)[])].*/\1/p')
|
||||
|
||||
# If there's no ID, skip
|
||||
[ -z "$id" ] && continue
|
||||
|
||||
# Remove the ID portion (and any leftover extra spaces)
|
||||
base=$(echo "$f" | sed 's/[([][^])]*[])]//g' | sed 's/ / /g' | sed 's/ *$//')
|
||||
|
||||
# Separate name and extension
|
||||
name="${base%.*}"
|
||||
ext="${base##*.}"
|
||||
|
||||
# Rebuild new name (handle files with and without extensions)
|
||||
if [ "$name" != "$ext" ]; then
|
||||
newname="${name} [${id}].${ext}"
|
||||
else
|
||||
newname="${base} [${id}]"
|
||||
fi
|
||||
|
||||
# Only rename if different
|
||||
[ "$f" != "$newname" ] && mv -- "$f" "$newname"
|
||||
done
|
||||
Loading…
x
Reference in New Issue
Block a user