#!/usr/bin/perl # This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. # http://herselfswebtools.com # Linda MacPhee-Cobb" #this program asks you for an old and new name and will change #the names of all the files in this directory from the old name #to the new name. Say you want to change joke1.htm joke2.htm etc #to riddle1.htm riddle2.htm joke will be the old string and riddle #will be the new string. #be sure to work on copies not your original data! print "\n\n Suppose you want to change all the files in"; print "\n this directory from joke123.html to riddle123.html"; print "\n joke would be the old string and riddle would be"; print "\n the new string."; print "\n\n * always work on a copy not your original files. * "; print "\n data could be lost otherwise if you mis-type something."; print "\n\n What is the old string? "; $oldstring = ; chomp ( $oldstring ); print "\n\n What is the new string? "; $newstring = ; chomp ( $newstring ); #get list of all files in directory and number of files opendir ( DIRECTORY, '.') or die ("can't open current directory "); @list = readdir ( DIRECTORY ); foreach $f ( @list ) { $oldname = $f; $newname = $f; $newname =~ s/$oldstring/$newstring/; #change the file name rename ( $oldname, $newname ); } close ( DIRECTORY );