#!/bin/bash # Bulk File Renamer - Renames multiple files using Xdialog inputs # Copyright (C) 2008 Samuele "~redShadow~" Santi # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . TEMP=/tmp/answer$$ LOGFILE=/tmp/logfile$$ OK="\033[0m[ \033[1;32mOK\033[0m ]" SKIP="\033[0m[ \033[1;33mSKIP\033[0m ]" FAILED="\033[0m[\033[1;31mFAILED\033[0m]" OK="[ OK ]" SKIP="[ SKIP ]" FAILED="[FAILED]" # Check if can use Xdialog - else dialog # if Xdialog --version &>/dev/null ; then # DIALOG='Xdialog' # else DIALOG='dialog' # if # ..but commented 'cause I just don't want graphical crap :) #echo "[DEBUG] using '$DIALOG' for displaying messages" >>$LOGFILE # ask how to rename each file while [ "$1" != "" ]; do oldfile="$1" # echo " * Renaming $oldfile" >&2 "$DIALOG" \ --ok-label "Rename" \ --stderr \ --title "Rename file" \ --inputbox "Original Filename: $oldfile" 8 80 "$oldfile" 2>$TEMP newfile="$( cat $TEMP )" echo -n " * Renaming \"$oldfile\" to \"$newfile\"... " >>$LOGFILE if [ "$?" == 0 ] && [ "$newfile" != "$oldfile" ] && [ "$newfile" != "" ]; then mv "$oldfile" "$newfile" && echo -e $OK >>$LOGFILE || echo -e $FAILED >>$LOGFILE else echo -e $SKIP >>$LOGFILE fi shift done # display output $DIALOG --title "Result log" --msgbox "$( cat $LOGFILE )" 100 600 # cat $LOGFILE >&2 #PROVA="`Xdialog --no-shadow --ok-label Rename --stdout --title "Rename file" --inputbox "Original Filename: file.txt" 8 80 "file.txt"`"