Add All existing
This commit is contained in:
27
rename_episodes
Executable file
27
rename_episodes
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Use the first argument as the directory or default to the current directory
|
||||
directory="${1:-$(pwd)}"
|
||||
|
||||
# Change to the specified directory
|
||||
cd "$directory" || { echo "Directory not found: $directory"; exit 1; }
|
||||
|
||||
# Regular expression to match " 00 ", " 01 ", ..., " 99 "
|
||||
for file in *; do
|
||||
if [[ "$file" =~ ([[:space:]]([0-9]{2})[[:space:]]) ]]; then
|
||||
# Extract the number (e.g., "00", "01")
|
||||
number="${BASH_REMATCH[2]}"
|
||||
|
||||
# Get the file extension
|
||||
extension="${file##*.}"
|
||||
[[ "$file" == "$extension" ]] && extension="" || extension=".$extension"
|
||||
|
||||
# Construct the new filename
|
||||
new_filename="E$number$extension"
|
||||
|
||||
# Rename the file
|
||||
mv -v "$file" "$new_filename"
|
||||
else
|
||||
echo "Skipped: $file (no match)"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user