You are not logged in.
Hi all,
I am working on a script to rename all the files of a tv show contain into a single folder - keeping season & episodes numbers.
I am using zenity to get the correct name of the tv show (mainly to add capital letters, and remove the dots - and also to be able to use the script for different tv show)
then again using zenity to select which folder contain the files, and then I want zenity to display how the rename will do as a verification and if happy then process.
The script work great but I can get zenity to display the output of the command and ask the question.
Any suggestion?
Many thanks,
Regards,
#!/bin/bash
#Use Zenity to capture the title of the TV Show
tv_show_name=$(zenity --entry)
#Select folder where the files to be rename are
sourcefolder=$(zenity --file-selection --directory --title "Please select the folder containing those Files")
#Move into the folder
cd $sourcefolder
#Now we execute the script to keep season and episode numbers
if [ $? == 1 ]; then exit; fi
for filename in *; do
if [[ "$filename" =~(\**).*(.*[0-9][0-9]).*([0-9][0-9]).*(\....)$ ]]; then
result=$(`echo mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}"`)
zenity --question --title="Are those title correct?" \
--text=$result \
if [[ $? -eq 0 ]] ; then exit; fi
else
mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}")
fi
done
exit
Offline
You should work a bit on your quotation signs
So far what I've seen:
cd "$sourcefolder"
" is neede if your directory has a space in it
result=$(echo mv \"$filename\" \"$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}\")
should let zenity show the titles
Offline
Yes you're right, but it still doesn't work.
See the terminal output:
[sweetth@myhost ~]$ '/home/sweetth/test-rn.sh'
/home/sweetth/test-rn.sh: line 18: syntax error near unexpected token `)'
/home/sweetth/test-rn.sh: line 18: `mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}")'
Offline
Offline
First of all many thanks for your assistance,
But I am unsure on how to use the code there?
Offline
sigh.
result=$(echo mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}")
Offline
Right I kind of understand the principle after reading about "foo bar baz"
But I still don't get your code, and how to display the result using zenity, I am actually more confuse than before?!
Offline
The point of the for loops I showed you is to demonstrate word splitting and quoting. I hate to be lame, but the adage 'you have to learn to walk before you can run' seems apropos here.
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/WordSplitting
Last edited by falconindy (2011-09-27 15:54:00)
Offline
No I appriciate the need to learn and this is why I play with those script. But I don't get your code.
I will read up your link to try to understand it,
Anyway many thanks for your time and assistance,
Offline
Right,
I finally got it!
Now the script work (tested with multiple files, different names) and the verification is to a singles files just to be sure not the mess up those episodes number.
#!/bin/bash
#Use Zenity to capture the title of the TV Show
tv_show_name=$(zenity --entry)
#Select folder where the files to be rename are
sourcefolder=$(zenity --file-selection --directory --title "Please select the folder containing those Files")
#Move into the folder
cd "$sourcefolder"
#Now we execute the script to keep season and episode numbers
if [ $? == 1 ]; then
exit
fi
for filename in *; do
if [[ "$filename" =~(\**).*(.*[0-9][0-9]).*([0-9][0-9]).*(\....)$ ]]; then
result=$(echo mv \"$filename\" \"$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}\")
zenity --question --title="Are those title correct?" \
--text="$result" \
if [[ $? == 0 ]] ; then
mv "$filename" "$tv_show_name S${BASH_REMATCH[2]} E${BASH_REMATCH[3]}${BASH_REMATCH[4]}"
fi
fi
done
exit
Offline
Homework done then? Don't forget to sign that authentic and original work statement
Offline