okay... so what do you think.... will this work? chatgot says it will .
#!/usr/bin/env bash

# Label of the drive
LABEL="photos"

# Get the mountpoint for the volume with this label
MOUNT_POINT=$(findmnt -n -o TARGET -S LABEL="$LABEL")

if [ -z "$MOUNT_POINT" ]; then
    echo "Could not find a mounted volume with label: $LABEL"
    exit 1
fi

echo "Found $LABEL mounted at: $MOUNT_POINT"

# Use the mounted directory as working dir
WORKING_DIR="$MOUNT_POINT"

cd "$WORKING_DIR" || { echo "Could not change to directory: $WORKING_DIR";
exit 1; }

# Define a loop counter
COUNTER=1

# Process all .txt files
while IFS= read -r FILE; do
    # Store the directory of the file
    DIR=$(dirname "$FILE" | tr '[:upper:]' '[:lower:]')

    # Strip the file extension and convert to lowercase
    OLD_NAME=$(basename "$FILE" | sed 's/\.txt$//' | tr '[:upper:]'
'[:lower:]')

    # Build the new filename
    NEW_NAME="${OLD_NAME}_${COUNTER}.txt"

    # Perform the renaming
    if mv "${DIR}/${OLD_NAME}.txt" "${DIR}/${NEW_NAME}"; then
        echo "Renamed '${DIR}/${OLD_NAME}.txt' -> '${DIR}/${NEW_NAME}'"
        COUNTER=$((COUNTER + 1))
    else
        echo "Failed to rename '$FILE'"
        exit 1
    fi
done < <(find . -type f -name "*.txt" | sort -u)

On Thu, Aug 7, 2025 at 2:33 PM Snyder, Alexander J <
[email protected]> wrote:

> I have actually written this a few times for things I've needed in my
> homelab:
>
> This is the code (at a glance):
> [image: image.png]
>
> I have attached the source file for you to use.  Please make note that it
> requires you to enter in your working directory (line 4) before it will
> work as intended.
>
> --
> Thanks,
> Alex.
>
>
>
>
> On Thu, Aug 7, 2025 at 10:06 AM Michael via PLUG-discuss <
> [email protected]> wrote:
>
>> I was wondering, I need to rename a sequence of files from
>> '<order>,jpg' '<order+1>,jpg' (etc)
>> to
>> '<name> - <name>.jpg' '<name> - <name>*sequence* <+1>'.jpg etc
>> Would someone give me the proper bash command to do it?
>> ---------------------------------------------------
>> PLUG-discuss mailing list: [email protected]
>> To subscribe, unsubscribe, or to change your mail settings:
>> https://lists.phxlinux.org/mailman/listinfo/plug-discuss
>>
>

-- 
:-)~MIKE~(-:
---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss

Reply via email to