The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-15-2008
Astrid Astrid is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
change file extension from root and subdirectories

Hello, my first post!
I'd appreciate help with this script, I'm new to this.

I have a media directory where I want to batch convert image file names from .img to .iso.

I've tried but get:
$ ./img2iso2.sh
./img2iso2.sh: line 13: syntax error: unexpected end of file

This is my unfinished script:
Code:
#!/bin/bash

# Set the video directory here
VIDEO_ROOT_DIRECTORY="/Users/astrid/NFS/scripts/img2iso/";

# Check if the directory exist or not
if [ -d "$VIDEO_ROOT_DIRECTORY" ]; then
	cd $VIDEO_ROOT_DIRECTORY
else
	print "ERROR: Unable to reach directory - or it does not exist!";
fi

for imgfile do 
    	case $imgfile *.img
            	do mv $imgfile.img $imgfile.iso;
               	done
          print "img-files renamed to iso";
    	esac
done

exit 0
I assume this doesn't check subdirectories, even though I'd like it to. Maybe a combination of find, grep and sed should be used instead? These commands seems to work marvels in almost any situation.

Also, I'd think it would be smart to include some sort of check:
if there is a file called image.iso and one called image.img in the same (sub)directory; I'd like to change the name of that .img file to image-1.iso. But I don't even know where to start with this check!

If I understand the error message there's a problem with quoting? I've made so many trials that I can't remember where I started anymore.

Any help is greatly appreciated.


EDIT:
Searching the forum I found a better way to do the replacement of the file extension (here), but I wasn't so lucky with the subdirs.

Last edited by Astrid; 02-15-2008 at 03:43 PM..