• GROK Made a Simple File Renamer

    From Dr. Noah Bodie@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Tue Sep 16 19:38:05 2025
    From Newsgroup: alt.os.linux.ubuntu

    This is similar to GPRename but not as sophisticated. You can rename all
    of the files in the current folder. Note: it is case sensitive (if you
    need this function) so you can switch cases on files, IE rename
    "Buster.txt" as "buster.txt"


    #!/bin/bash

    # Check if zenity is installed
    if ! command -v zenity &> /dev/null; then
    echo "Zenity is required but not installed. Please install it using
    'sudo apt-get install zenity' or equivalent."
    exit 1
    fi

    # Get search string from user
    search_string=$(zenity --entry \
    --title="Search String" \
    --text="Enter characters to search for:" \
    --width=300)

    # Check if user cancelled
    if [ $? -ne 0 ]; then
    exit 0
    fi

    # Check if search string is empty
    if [ -z "$search_string" ]; then
    zenity --error --text="Search string cannot be empty!" --width=200
    exit 1
    fi

    # Get replace string from user
    replace_string=$(zenity --entry \
    --title="Replace String" \
    --text="Enter characters to replace with:" \
    --width=300)

    # Check if user cancelled
    if [ $? -ne 0 ]; then
    exit 0
    fi

    # Count files that will be renamed
    count=0
    for file in *; do
    if [[ "$file" == *"$search_string"* ]]; then
    ((count++))
    fi
    done

    # If no files match, inform user and exit
    if [ $count -eq 0 ]; then
    zenity --info --text="No files found containing '$search_string'." --width=200
    exit 0
    fi

    # Perform rename operation
    for file in *; do
    if [[ "$file" == *"$search_string"* ]]; then
    new_name="${file//$search_string/$replace_string}"
    if [ "$file" != "$new_name" ]; then
    mv -n "$file" "$new_name"
    if [ $? -eq 0 ]; then
    echo "Renamed: $file -> $new_name"
    else
    zenity --error --text="Error renaming $file to
    $new_name" --width=200
    fi
    fi
    fi
    done

    # Show completion message
    zenity --info --text="Renaming complete. $count file(s) processed." --width=200
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Alan K.@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 09:08:05 2025
    From Newsgroup: alt.os.linux.ubuntu

    On 9/16/25 6:38 PM, Dr. Noah Bodie wrote:
    This is similar to GPRename but not as sophisticated. You can rename all
    of the files in the current folder. Note: it is case sensitive (if you
    need this function) so you can switch cases on files, IE rename
    "Buster.txt" as "buster.txt"


    #!/bin/bash

    # Check if zenity is installed
    if ! command -v zenity &> /dev/null; then
    echo "Zenity is required but not installed. Please install it using 'sudo apt-get install zenity' or equivalent."
    exit 1
    fi

    # Get search string from user
    search_string=$(zenity --entry \
    --title="Search String" \
    --text="Enter characters to search for:" \
    --width=300)

    # Check if user cancelled
    if [ $? -ne 0 ]; then
    exit 0
    fi

    # Check if search string is empty
    if [ -z "$search_string" ]; then
    zenity --error --text="Search string cannot be empty!" --width=200
    exit 1
    fi

    # Get replace string from user
    replace_string=$(zenity --entry \
    --title="Replace String" \
    --text="Enter characters to replace with:" \
    --width=300)

    # Check if user cancelled
    if [ $? -ne 0 ]; then
    exit 0
    fi

    # Count files that will be renamed
    count=0
    for file in *; do
    if [[ "$file" == *"$search_string"* ]]; then
    ((count++))
    fi
    done

    # If no files match, inform user and exit
    if [ $count -eq 0 ]; then
    zenity --info --text="No files found containing '$search_string'." --width=200
    exit 0
    fi

    # Perform rename operation
    for file in *; do
    if [[ "$file" == *"$search_string"* ]]; then
    new_name="${file//$search_string/$replace_string}"
    if [ "$file" != "$new_name" ]; then
    mv -n "$file" "$new_name"
    if [ $? -eq 0 ]; then
    echo "Renamed: $file -> $new_name"
    else
    zenity --error --text="Error renaming $file to
    $new_name" --width=200
    fi
    fi
    fi
    done

    # Show completion message
    zenity --info --text="Renaming complete. $count file(s) processed." --width=200

    Interesting examples of what can be done in bash, but why?
    I mean gprename or bulky are usually always available and have so many more uses.
    --
    Linux Mint 22.2, Thunderbird 128.14.0esr, Mozilla Firefox 142.0.1
    Alan K.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Dr. Noah Bodie@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 13:04:16 2025
    From Newsgroup: alt.os.linux.ubuntu

    On 2025-09-17 10:08 AM, Alan K. wrote:
    Interesting examples of what can be done in bash, but why?
    I mean gprename or bulky are usually always available and have so many
    more uses.


    That is true, but I made this because using gprename can be a *bit* troublesome if you have to navigate to deeply nested sub-folders.
    If gprename let you "copy & paste" a destination URL then I would not
    have made this script.

    As it was I had 6 folders that contained files that needed to be bulk re-named, but since each folder was in a different location navigating
    to each folder was a small hassle.

    This simple script lets me do bulk re-naming much faster because I can
    drag and drop the bash file into a folder and run it.

    what i would like to do is find a way to make this script open in the
    current folder just by clicking a link, but i doubt that Linux has an
    option that permits that function.

    or is there a way to make gprename open in the current folder?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From yossarian@alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 20:16:12 2025
    From Newsgroup: alt.os.linux.ubuntu

    On Wed, 17 Sep 2025 13:04:16 -0300
    "Dr. Noah Bodie" <[email protected]> wrote:
    or is there a way to make gprename open in the current folder?
    Yes there is a way
    From Nemo open folder you want in terminal and type gprename and it
    opens gprename in that folder. Or you mind something else.
    --
    Running Linux Mint 22.2 (Zara) using Kernel=6.14.0-29-generic on x86_64
    , Cinnamon, lightdm, x11
    AMD Ryzen 7 5700G with Radeon Graphics (16) @ 5.288GHz
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Alan K.@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 14:36:24 2025
    From Newsgroup: alt.os.linux.ubuntu

    On 9/17/25 2:16 PM, yossarian wrote:
    On Wed, 17 Sep 2025 13:04:16 -0300
    "Dr. Noah Bodie" <[email protected]> wrote:

    or is there a way to make gprename open in the current folder?
    Yes there is a way
    From Nemo open folder you want in terminal and type gprename and it
    opens gprename in that folder. Or you mind something else.

    The OP can do similar with his script. If you make a ~/bin folder and put your script
    there, you could do the same as above but use your script name instead of gprename.

    A more involved option is making a nemo action. I've made a dozen or so. They show up in
    the right click menu.

    Here is a link to a bunch of them. https://github.com/smurphos/nemo_actions_and_cinnamon_scripts
    The action file goes in ~/.local/share/nemo/actions
    Scripts (if any) usually go in ~/.local/share/nemo/actions/scripts
    I like the 'set execute' and 'touch file' and 'xed sudo-edit' actions.

    There is a sample action in the smurphos download and it's rather detailed as to what you
    need to make one work. You (the OP) seem to be good at scripting so it would just be a
    matter of putting the parts together.
    --
    Linux Mint 22.2, Thunderbird 128.14.0esr, Mozilla Firefox 142.0.1
    Alan K.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Paul@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 16:07:57 2025
    From Newsgroup: alt.os.linux.ubuntu

    On Tue, 9/16/2025 6:38 PM, Dr. Noah Bodie wrote:
    This is similar to GPRename but not as sophisticated. You can rename all of the files in the current folder. Note: it is case sensitive (if you need this function) so you can switch cases on files, IE rename "Buster.txt" as "buster.txt"


    #!/bin/bash
    ...
    # Perform rename operation
    for file in *; do
    ��� if [[ "$file" == *"$search_string"* ]]; then
    ������� new_name="${file//$search_string/$replace_string}"
    ������� if [ "$file" != "$new_name" ]; then
    ����������� mv -n "$file" "$new_name"
    ����������� if [ $? -eq 0 ]; then
    ��������������� echo "Renamed: $file -> $new_name"
    ����������� else
    ��������������� zenity --error --text="Error renaming $file to $new_name" --width=200
    ����������� fi
    ������� fi
    ��� fi
    done

    Your error dialog, needs some choices. This is a crude example.

    else
    # zenity --error --text="Error renaming $file to $new_name" --width=200
    zenity --question --text "Error renaming $file to $new_name" --ok-label="Continue" --cancel-label="Cancel"
    if [ $? -ne 0 ]; then
    exit 1
    fi
    fi

    In the picture, I clicked "Continue" the first time, and "Cancel" the
    second time the dialog appeared.

    [Picture]

    https://i.postimg.cc/FzxG5Bkj/zenity-dialog.gif

    Paul
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Dr. Noah Bodie@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 18:19:36 2025
    From Newsgroup: alt.os.linux.ubuntu

    "Dr. Noah Bodie" <[email protected]> wrote:
    or is there a way to make gprename open in the current folder?


    On 2025-09-17 3:16 PM, yossarian < wrote:>
    Yes there is a way
    From Nemo open folder you want in terminal and type gprename and it
    opens gprename in that folder. Or you mind something else.

    That does exactly what I wanted. Thnx!
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Wed Sep 17 23:01:43 2025
    From Newsgroup: alt.os.linux.ubuntu

    On Wed, 17 Sep 2025 13:04:16 -0300, Dr. Noah Bodie wrote:

    what i would like to do is find a way to make this script open in the current folder just by clicking a link, but i doubt that Linux has an
    option that permits that function.

    Why didn’t you ask the AI about that?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Dr. Noah Bodie@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Fri Sep 19 16:51:33 2025
    From Newsgroup: alt.os.linux.ubuntu

    On 2025-09-17 10:08 AM, Alan K. wrote:
    Interesting examples of what can be done in bash, but why?
    I mean gprename or bulky are usually always available and have so many
    more uses.

    Well, I just discovered that GPRENAME will NOT work on my external HDD,
    seems it can't even detect it. I needed to rename over a dozen files and
    this script did the job while GPRENAME could not.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Alan K.@[email protected] to alt.os.linux.ubuntu,alt.os.linux.mint on Fri Sep 19 17:00:04 2025
    From Newsgroup: alt.os.linux.ubuntu

    On 9/19/25 3:51 PM, Dr. Noah Bodie wrote:
    On 2025-09-17 10:08 AM, Alan K. wrote:
    Interesting examples of what can be done in bash, but why?
    I mean gprename or bulky are usually always available and have so many
    more uses.

    Well, I just discovered that GPRENAME will NOT work on my external HDD,
    seems it can't even detect it. I needed to rename over a dozen files and
    this script did the job while GPRENAME could not.
    It has issues with some . folders too. It has it quirks.
    --
    Linux Mint 22.2, Thunderbird 128.14.0esr, Mozilla Firefox 143.0
    Alan K.
    --- Synchronet 3.21a-Linux NewsLink 1.2