28 lines
762 B
Bash
Executable File
28 lines
762 B
Bash
Executable File
#!/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
|