41 lines
1.0 KiB
Bash
Executable File
41 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check for arguments and set variables
|
|
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
|
|
echo "Usage: $0 {FOLDER} YYYY_MM_DD YYYY_MM_DD"
|
|
exit 1
|
|
fi
|
|
|
|
# Set folder path
|
|
if [ "$#" -eq 3 ]; then
|
|
TARGET_DIR="$1"
|
|
START_DATE="$2"
|
|
END_DATE="$3"
|
|
else
|
|
TARGET_DIR="."
|
|
START_DATE="$1"
|
|
END_DATE="$2"
|
|
fi
|
|
|
|
# Ensure the target directory exists
|
|
mkdir -p "$TARGET_DIR"
|
|
|
|
# Convert input dates to YYYY-MM-DD format for `date` compatibility
|
|
START_DATE=$(echo "$START_DATE" | sed 's/_/-/g')
|
|
END_DATE=$(echo "$END_DATE" | sed 's/_/-/g')
|
|
|
|
# Loop through dates and create folders
|
|
current_date="$START_DATE"
|
|
while [[ "$current_date" < "$END_DATE" ]] || [[ "$current_date" == "$END_DATE" ]]; do
|
|
# Format date as YYYY_MM_DD
|
|
formatted_date=$(date -d "$current_date" +"%Y_%m_%d")
|
|
|
|
# Create folder with the formatted date
|
|
mkdir -p "$TARGET_DIR/$formatted_date"
|
|
|
|
# Increment date by one day
|
|
current_date=$(date -I -d "$current_date + 1 day")
|
|
done
|
|
|
|
echo "Folders created from ${START_DATE//-/_} to ${END_DATE//-/_} in $TARGET_DIR."
|