35 lines
702 B
Bash
Executable File
35 lines
702 B
Bash
Executable File
#!/bin/bash
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 <filename>"
|
|
exit 1
|
|
fi
|
|
|
|
TARGET="$1"
|
|
|
|
if [ ! -f "$TARGET" ]; then
|
|
echo "Error: File '$TARGET' not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Extract just the filename (e.g., "Lecture_1.pdf")
|
|
# and the directory path (e.g., ".")
|
|
FILENAME=$(basename "$TARGET")
|
|
DIRNAME=$(dirname "$TARGET")
|
|
|
|
BTIME=$(stat -c %W "$TARGET")
|
|
|
|
if [ "$BTIME" -eq 0 ] || [ "$BTIME" == "-" ]; then
|
|
BTIME=$(stat -c %Y "$TARGET")
|
|
fi
|
|
|
|
FORMATTED_DATE=$(( BTIME / 60 ))
|
|
|
|
# Construct the new name using ONLY the filename,
|
|
# then prepend the original directory path
|
|
NEW_NAME="${DIRNAME}/${FORMATTED_DATE} - ${FILENAME}"
|
|
|
|
mv "$TARGET" "$NEW_NAME"
|
|
|
|
echo "Renamed: '$TARGET' -> '$NEW_NAME'"
|