42 lines
1.1 KiB
Bash
42 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
COURSE_FOLDER="$(pwd)"
|
|
|
|
# Kiểm tra tham số
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 ext1,ext2,..."
|
|
exit 1
|
|
fi
|
|
|
|
# Tạo mảng extension
|
|
IFS=',' read -ra EXT_ARRAY <<< "$1"
|
|
|
|
# Quét tất cả thư mục con
|
|
mapfile -t DIRS < <(find "$COURSE_FOLDER" -type d)
|
|
|
|
for dir in "${DIRS[@]}"; do
|
|
relative_path="${dir#*/vod/}"
|
|
OUTPUT_FILE="$dir/filelist.txt"
|
|
rm -f "$OUTPUT_FILE"
|
|
|
|
# Duyệt tất cả file trong thư mục
|
|
for file in "$dir"/*; do
|
|
[ -f "$file" ] || continue
|
|
filename=$(basename "$file")
|
|
ext="${filename##*.}"
|
|
# Kiểm tra extension có trong danh sách không
|
|
for allowed_ext in "${EXT_ARRAY[@]}"; do
|
|
if [[ "${ext,,}" == "${allowed_ext,,}" ]]; then # ignore case
|
|
echo "$relative_path/$filename" >> "$OUTPUT_FILE"
|
|
break
|
|
fi
|
|
done
|
|
done
|
|
|
|
# Sắp xếp tự nhiên filelist.txt
|
|
if [ -s "$OUTPUT_FILE" ]; then
|
|
sort -V -o "$OUTPUT_FILE" "$OUTPUT_FILE"
|
|
echo "File filelist.txt created successfully in $dir."
|
|
fi
|
|
done
|