2 # This script recurses a directory and creates a similar structure
3 # but converting the files from a given format to a different one.
5 # This program is copyright 2009 by Javier Fernandez-Sanguino <jfs@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # For more information please see
22 # http://www.gnu.org/licenses/licenses.html#GPL
30 convert_recurse_dir($sourcedir."/".$oldformat);
33 sub convert_recurse_dir ($) {
36 print "Looking $dir\n";
37 opendir $DIRFH, $dir || die ("Cannot open directory $dir: $!");
39 while ( $file = readdir($DIRFH) ) {
40 next if $file =~ /^\./; # Skip hidden files and directories
41 $filename = $dir."/".$file;
42 print "Checking $filename\n";
43 if ( -d "$filename" ) {
45 $newdir =~ s/\/$oldformat\//\/$newformat\//;
46 if ( ! -d "$newdir" ) {
47 print "Creating $newdir\n";
50 convert_recurse_dir($filename);
52 if ( -f "$filename" ) {
55 print "Done with $filename\n";
64 $newfile =~ s/\/$oldformat\//\/$newformat\//;
65 $newfile =~ s/\.$oldformat$/\.$newformat/;
66 if ( ! -e "$newfile" ) {
67 print "Converting $file to $newfile\n";
68 `convert $file $newfile`;