Files
Documentation/SH/rename_topics.sh
2025-09-14 23:13:06 +07:00

15 lines
536 B
Bash

#!/bin/bash
# Lấy thư mục hiện hành nơi người dùng đang gọi lệnh
TARGET_DIR="$(pwd)"
# Đổi tên các thư mục con cấp 1 theo mẫu: 1 - ABC → 1. ABC
find "$TARGET_DIR" -mindepth 1 -maxdepth 1 -type d -regextype posix-extended -regex '.*/[0-9]+ - .+' | while read dir; do
base=$(basename "$dir")
newname=$(echo "$base" | sed -E 's/^([0-9]+) - (.+)$/\1. \2/')
if [ "$base" != "$newname" ]; then
echo "🔁 Đổi tên: $base$newname"
mv "$TARGET_DIR/$base" "$TARGET_DIR/$newname"
fi
done