Update code
This commit is contained in:
22
Moodle/SH/removeblank.sh
Normal file
22
Moodle/SH/removeblank.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
BASE_DIR="."
|
||||
|
||||
find "$BASE_DIR" -depth | while IFS= read -r path; do
|
||||
current_name=$(basename "$path")
|
||||
parent_dir=$(dirname "$path")
|
||||
|
||||
# Loại bỏ ký tự đặc biệt: # ! ' [ ] @ bằng tr + tr -d
|
||||
new_name=$(echo "$current_name" | tr -d "#!'\[\]@")
|
||||
|
||||
# Loại bỏ khoảng trắng thừa (chỉ giữ 1 dấu cách, loại bỏ cuối)
|
||||
new_name=$(echo "$new_name" | tr -s ' ' | sed 's/ *$//')
|
||||
|
||||
# Nếu tên thay đổi thì đổi tên
|
||||
if [[ "$current_name" != "$new_name" ]]; then
|
||||
mv -- "$path" "$parent_dir/$new_name"
|
||||
echo "Đã đổi tên: '$path' → '$parent_dir/$new_name'"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "✅ Hoàn thành."
|
Reference in New Issue
Block a user