home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.os.linux.ubuntu      I preferred Xubuntu, seemed a bit faster      134,474 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 134,383 of 134,474   
   Dr. Noah Bodie to All   
   GROK Made a Simple File Renamer   
   16 Sep 25 19:38:05   
   
   XPost: alt.os.linux.mint   
   From: noah@bodie.not   
      
   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   
      
   --- 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