From: Chris Koeritz Date: Sat, 3 Aug 2013 18:44:05 +0000 (-0400) Subject: retired bash version of change prefix in favor of cleaned up retread of change suffix. X-Git-Tag: 2.140.90~955 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=ab2a48e90c0f3778c267862bc125d5f2d4b3bb73;p=feisty_meow.git retired bash version of change prefix in favor of cleaned up retread of change suffix. also fixed docs in change suffix. --- diff --git a/scripts/files/change_prefix.pl b/scripts/files/change_prefix.pl new file mode 100644 index 00000000..e6d22f43 --- /dev/null +++ b/scripts/files/change_prefix.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +############## +# Name : change_prefix +# Author : Chris Koeritz +# Rights : Copyright (C) 2002-$now by Author +############## +# Purpose: +# Replaces all of the matching first portions of files in the current +# directory with a different chunk. The first parameter should be the old +# prefix and the second parameter should be the new prefix. +############## +# This script is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the License or (at your option) +# any later version. See "http://www.fsf.org/copyleft/gpl.html" for a copy +# of the License online. Please send any updates to "fred@gruntose.com". +############## + +require "filename_helper.pl"; + +local($first) = $ARGV[0]; +local($second) = $ARGV[1]; + +#print "parms are: $first and $second \n"; + +if ( !length($first) || !length($second) ) { + print "change_prefix: requires two parameters--the old prefix to look for in this\n"; + print "directory and the new prefix to replace the old suffix with.\n"; + exit 0; +} + +foreach $filename (&glob_list("./$first*")) { + local $new_name = $filename; + $new_name =~ s/$first/$second/g; +#print "old name $filename\n"; +#print "new name will be $new_name\n"; + system("mv \"$filename\" \"$new_name\""); +} + + diff --git a/scripts/files/change_prefix.sh b/scripts/files/change_prefix.sh deleted file mode 100644 index b9ab9028..00000000 --- a/scripts/files/change_prefix.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# change_prefix: takes all of the files in the current directory starting in $1 -# and modifies their prefix to be $2. - -if [ $# -lt 2 ]; then - echo \ -"$(basename $0): requires two parameters--the old prefix to look for in this directory" - echo "and the new prefix (without dots) to change the prefix to." - \exit 2 -fi -for i in *; do - if [ ! -z "$(echo $i | sed -n -e "s/^\($1\).*\..*$/\1/p")" ]; then - extrabit="$(echo $i | sed -n -e "s/^$1\(.*\)\..*$/\1/p")" - suffix="$(echo $i | sed -n -e "s/^$1.*\.\(.*\)$/\1/p")" -#echo extrabit is $extrabit -#echo suff is $suffix - mv "$i" "$2$extrabit.$suffix" - fi -done diff --git a/scripts/files/change_suffix.pl b/scripts/files/change_suffix.pl index 97945e16..0854f44c 100644 --- a/scripts/files/change_suffix.pl +++ b/scripts/files/change_suffix.pl @@ -1,27 +1,21 @@ #!/usr/bin/perl -############################################################################### -# # -# Name : change endings # -# Author : Chris Koeritz # -# Rights : Copyright (C) 2002-$now by Author # -# # -# Purpose: # -# # -# Replaces all of the endings on files in the current directory with # -# a different ending. The first parameter should be the old ending and the # -# second parameter should be the new ending. # -# # -############################################################################### -# This script is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; either version 2 of the License or (at your option) # -# any later version. See "http://www.fsf.org/copyleft/gpl.html" for a copy # -# of the License online. Please send any updates to "fred@gruntose.com". # -############################################################################### - -# change_endings: takes all of the files in the current directory ending in $1 -# and modifies their suffix to be $2. +############## +# Name : change_suffix +# Author : Chris Koeritz +# Rights : Copyright (C) 2002-$now by Author +############## +# Purpose: +# Replaces all of the matching endings on files in the current directory +# with a different ending. The first parameter should be the old ending and +# the second parameter should be the new ending. +############## +# This script is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the License or (at your option) +# any later version. See "http://www.fsf.org/copyleft/gpl.html" for a copy +# of the License online. Please send any updates to "fred@gruntose.com". +############## require "filename_helper.pl"; @@ -31,23 +25,16 @@ local($second) = $ARGV[1]; #print "parms are: $first and $second \n"; if ( !length($first) || !length($second) ) { - print "change_endings: requires two parameters--the old suffix to look for in this\n"; - print "directory and the new suffix (without dots) to change the old suffix to.\n"; + print "change_suffix: requires two parameters--the old suffix to look for in this\n"; + print "directory and the new suffix to replace the old suffix with.\n"; exit 0; } foreach $filename (&glob_list("./*$first")) { -#old print "file=$filename\n"; -#old local($ext_temp) = &extension($filename); -#old print "ext is: $ext_temp\n"; -#old local($no_ext) = &non_extension($filename); -#old print "cmd is: mv \"$filename\" \"$no_ext$second\"\n"; -#old system("mv \"$filename\" \"$no_ext$second\""); - local $new_name = $filename; $new_name =~ s/$first/$second/g; #print "old name $filename\n"; -#print "new name would be $new_name\n"; +#print "new name will be $new_name\n"; system("mv \"$filename\" \"$new_name\""); }