Page 1 of 1

[Linux] Rename Movie.img > Movie.iso

Posted: October 31st, 2010, 9:05 am
by Eejit
I have no idea about Linux, but have searched here and 'tintenet for help and ideas.

I have SAB running on an Xtreamer eTrayz, and use an Xtreamer Pro to play my media.
The Xtreamer Pro will not play .img files unless they are renamed .iso

I want to create a script for my movie catagories that will check if it's an .img that's been downloaded, and if so, rename it to .iso
Obviously it would have to check in any sub directories.

This is what I have managed to cobble together so far.  My question is, will it work? and is there a simpler/better way to do this?

Code: Select all


#!/bin/bash
cd "$1"
for name in `ls -R *.img` 
do 
name1=`echo $name | sed -e 's/^\(.*\)\.img$/\1\.iso/g'` 
mv $name $name1
done


Re: [Linux] Rename Movie.img > Movie.iso

Posted: October 31st, 2010, 3:07 pm
by Eejit
OK, that didn't work for the sub directories. This did though.

Code: Select all

#!/bin/bash
cd "$1"
for name in `find -name "*.img"` 
do 
name1=`echo $name | sed -e 's/^\(.*\)\.img$/\1\.iso/g'` 
mv $name $name1
done
This works if none of the subdirectories don't have any spaces, eg "New.Folder" but if it has spaces, "New Folder" then I get errors.

Any suggestions as to how to fix this?

Re: [Linux] Rename Movie.img > Movie.iso

Posted: October 31st, 2010, 5:07 pm
by Eejit
Finaly got it to work. This will rename all ".img" to ".iso" regardless of any spaces in the filename or any sub directory name.
Possibly can be done more elegantly, but it works for me  ;D

Code: Select all

#!/bin/bash
old_IFS="$IFS"
cd "$1"
IFS=$'\t\n'
for name in `find -name "*.img"` 
do 
name1=`echo $name | sed -e 's/^\(.*\)\.img$/\1\.iso/g'` 
echo "Renaming " $name " to " $name1
mv $name $name1
done
IFS=$old_IFS