Slow Progress

I'm still around, working on the site slowly... Mostly on the backend or planning out the content; though you might have noticed some visual changes since the last time I posted (I'm constantly messing with the CSS file.. probably spending way too much time on that aspect, actually). But anyway, I made it easier to customize specific borders of the various visual objects (gives more of a theme vibe now), which is most notable with the navigation menu above having curved lines, as well as hyper-links now looking more like a 'button' vs just underlined text (as seen in the next paragraph).

I did add the landing page for the Land of "GenAI" section, with the intention of having that entire area done by this weekend... but I either got distracted with 'real world' stuff or was pondering how I wanted to go about the layout. For example, I plan to separate the artwork section between DALL-E and Stable Diffusion pages, but still working out exactly how to sub divide it from there.. or how I want go about showcasing the art. I did find a nice 'art gallery guide' over at Solaria's Webspace, one of the few Neocities sites I'm currently following on my profile. Quite a few good web design tutorials over there, for those interested.

Filename Bash?

One hurtle I didn't expect to run into was the image filenames. So when I started collecting the DALL-E renders from my old ChatGPT conversations.. it became quite apparent that I would have to rename all these files before uploading them (for those that aren't aware.. when you download a DALL-E render, it puts a good chunk of the text prompt in the filename itself.. so you end up with these paragraph long, un-web friendly filenames). Originally, I was going to do the usual 'select all files, F2, rename' method for batch renaming of files, but this also led to a format I didn't care for... so, it was time to make a custom script.


#!/bin/bash

echo ""
echo "Running bin/bash script 'batch_rename_files.sh'"

# Check if an argument was provided, otherwise exit with an error message
if [ -z "$1" ]; then
  echo "Usage: $0 'new_filename_label'"
  exit 1
fi

# Set the title from the first argument
LABEL="$1"

# Set the source directory to the current directory where the script is located
SOURCE_DIR="$(pwd)"

# Define the target directory as a subdirectory of the current directory
TARGET_DIR="$SOURCE_DIR/renamed_files_to_$LABEL"

# Get the full path of the script
SCRIPT_FILE="$(realpath "$0")"

echo "-- Ready to copy files..."
echo "-- from: $SOURCE_DIR"
echo "-- to: $TARGET_DIR"
echo "-- Renaming each copied file to: $LABEL-<####>.<ext>"
read -p "-- Continue (Y/N)?: " choice

# Convert the choice to uppercase to make the input case-insensitive
choice=$(echo "$choice" | tr '[:lower:]' '[:upper:]')

# Check if the user entered 'Y' to continue
if [ "$choice" != "Y" ]; then
  echo "Operation cancelled..."
  exit 0
fi

# Make sure the target directory exists
mkdir -p "$TARGET_DIR"

# Initialize a counter
counter=1

# Loop through the files (and directories) in the source directory
for file in "$SOURCE_DIR"/*; do
  # Skip the script file itself and any directories
  if [[ "$file" == "$SCRIPT_FILE" || ! -f "$file" ]]; then
    echo "---- Item skipped: $file"
    continue
  fi

  # Store the filename without it's filepath
  filename=$(basename "$file")

  # Get the file extension
  extension="${file##*.}"

  # Format the counter to be a 4-digit number with leading zeros
  formatted_counter=$(printf "%04d" "$counter")

  # Define the new file name
  new_filename="$LABEL-$formatted_counter.$extension"

  echo "---- $counter - File copied: $filename"

  # Copy the file to the target directory with the new name
  cp "$file" "$TARGET_DIR/$new_filename"

  # Increment the counter
  ((counter++))
done

echo "-- $counter files have been renamed to $LABEL and copied to $TARGET_DIR"
echo "Operation completed!"
      

Example usage:


./batch_rename_files.sh "example_filename"
      

So I ended up making a quick Bash script for this particular task (again... probably spent way too much time on this).

Once you have created the script, it's as simple as putting the batch_rename_files.sh file into the directory you want to rename all the files in and then run it via terminal with the label you want to rename all the files to. It makes a new sub-directory and then copies all the files in our current directory to the new sub-directory with each file named with 'new name + a number' (so as a bonus, it leaves the original files un-altered). I plan to expand the script to support a more printf() approach for customiziable output results... but, I already spent way too much time on this particular aspect (and it generates the results I currently need). Tho, I thought I'd share it for others who may want something similar.

With that said, I can't take all the credit, as it takes heavy inspiration from code that ChatGPT generated (I don't use Bash often.. so while I understand how to go about the process in languages like Lua or C/C++, I wasn't sure of the particulars with Bash scripting). For those curious about how I arrived at this code, here is a link to the entire converstation with ChatGPT. Admittedly, I got somewhat lazy during the converstation and would ask for it to add sections to the script instead of searching 'how to do x' on my own (notably, the part where I ask about a confirmnation question, was mostly because I didn't know what the command for getting input from the terminal user was. I would never have guessed 'read').

But I was impressed with how ChatGPT would add parts to the script that I didn't think of adding; like when I told it I wanted the script to be executed from inside the directory I was pulling filenames from, it smartly added a check in the for loop to avoid copying itself over (even if it didn't quite hit the mark on the first pass and I had to point that out to it). Overall, large language models like ChatGPT or Claude AI can be quite a resource for software developers.

But what about the images?

I did get quite a few images uploaded to the site, which I'll post 2 examples below, but still haven't got around to getting the gallery itself done.. so that will be for a later update. With that, time to head off (but then I'll spend like the next <edit: 1 hour.. and I'm still not fully satisfied, but have to take a break> after typing this post getting these images to display nice =P).