#!/usr/bin/perl # renfiles.prl == changes filenames in and below a subdirectory # # files of a certain filename format ($file_glob) # in a specified directory ($start_dir) or any subdirectory below that # renfiles.prl copyright claimed by Chris Evans (C.Evans@sghms.ac.uk) -- June 1996 # You're welcome to redistribute or use this file as you like provided that you # a) don't make a profit out of it # b) don't remove this copyright declaration # You may change the file for your own use as much as you like, but # if you give that changed version to others please let me know: # a) what you changed and why (I write bad code and am happy to incorporate # improvements with acknowledgements) # b) whether you are keeping acknowledgement to me (I'd like it!!!) # c) whether you plan to make money out of it (highly unlikely I'd say!!!) $start_dir = "."; # where to start find finding files $file_glob = "musage.set"; # target files to process $new_glob = "musage.tes"; $verbose = 1; # gives file names as it goes # now run through all subdirectories looking for files open(FIND, "find $start_dir -name \"$file_glob\" -print |") || die "Couldn't run find: $!\n"; if (!FIND) { print "\n\nNo files matching $file_glob found in or below $start_dir\n\n"}; while ($filename = ) { chop($filename); print "\nProcessing file: $filename...\n" if ($verbose); $newname = $filename; $newname =~ s/(.*)($file_glob)/$1$new_glob/; rename($filename, $newname) || die "Couldn't rename $filename as $backname\n"; }