Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.os.linux.mint    |    Looks pretty on the outside, thats it!    |    30,566 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 29,170 of 30,566    |
|    Alan K. to Dr. Noah Bodie    |
|    Re: GROK Made a Simple File Renamer    |
|    17 Sep 25 09:08:05    |
   
   XPost: alt.os.linux.ubuntu   
   From: alan@invalid.com   
      
   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.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca