I wort a bash script it looks like this:
#!/bin/bash
D=`zenity --entry --entry-text='Folder'`
pattern1=`zenity --entry --entry-text='replace'`
pattern2=`zenity --entry --entry-text='by'`
cd "$D"
rename "s/$pattern1/$pattern2/g" *
zenity --info --text="Done"
it works very well.
I add it to nautilus scrips folder (~/.gnome2/nautilus-scripts),
and I make some changes :
#!/bin/bash
pattern1=`zenity --entry --entry-text='replace'`
if [ "$?" -eq 1 ]
then
exit
fi
pattern2=`zenity --entry --entry-text='by'`
if [ "$?" -eq 1 ]
then
exit
fi
rename "s/$pattern1/$pattern2/g" \'$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS\'
zenity --info --text="Done"
but it does not work.
I hope that I find some help
thanks in advance.
Problem resolved,by two ways. the first one:
using a for loop:
#!/bin/bash
pattern1=`zenity --entry --entry-text='replace'`
if [ "$?" -eq 1 ]
then
exit
fi
pattern2=`zenity --entry --entry-text='by'`
if [ "$?" -eq 1 ]
then
exit
fi
for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
rename "s/$motif1/$motif2/g" "$file"
done
zenity --info --text="Done"
the second : using a while loop:
#!/bin/bash
pattern1=`zenity --entry --entry-text='replace'`
if [ "$?" -eq 1 ]
then
exit
fi
pattern2=`zenity --entry --entry-text='by'`
if [ "$?" -eq 1 ]
then
exit
fi
echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS | while read 'file'
do
rename "s/$motif1/$motif2/g" "$file"
done
zenity --info --text="Done"
the question now is why I have to do that
and the answer is because $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS is a sequence
even if one file is selected we will find in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS the file selected path and a separator character
you can see that by using this commande:(add it to the script)
zenity --entry --entry-text="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
I hope that this can be usefull for someone
Inspired by that