#!/bin/bash

# Function to update the creation date (simulated via access and modification times)
update_creation_date() {
    local file="$1"

    # Get the modified time of the file
    modified_time=$(stat -c %y "$file")
    
    # Format the modified time into a valid touch format (YYYYMMDDhhmm.ss)
    formatted_time=$(date -d "$modified_time" +"%Y%m%d%H%M.%S")

    echo "Updating creation date for: $file"
    echo "Modified time: $modified_time"
    echo "Formatted time: $formatted_time"

    # Update access and modification times to match the modified time
    touch -t "$formatted_time" "$file"
}

# Function to process all files in a directory and its subdirectories
process_directory() {
    local directory="$1"

    # Find all files and loop through them
    find "$directory" -type f | while read -r file; do
        update_creation_date "$file"
    done
}

# Main script execution
read -p "Enter the path to the directory: " directory_path

if [[ ! -d "$directory_path" ]]; then
    echo "Error: Directory $directory_path does not exist."
    exit 1
fi

process_directory "$directory_path"