On Sat, Feb 03, 2007 at 05:33:42PM -0500, Paul Davis wrote: > long time *nix users will know that spaces have always been legal in > file names; new *nix users won't know that the oldtimers have never > really used them :) > doesn't everyone have a perl script that fixes spaces in files? ... they should: #!/usr/bin/perl -w ### fix_fn_keep_ext.pl ### if( ! defined($ARGV[0]) ){ die "$0 <file>[files...]\n"; } foreach ( @ARGV ){ if( -f $_ ){ rename( $_ , fix_fn( $_ ) ); } else { die "$file is not a file(or doesn\'t exist)"; } } ######################################### sub fix_fn { # string my($fn); my(@fn_arr); if(defined($_[0])){ $fn = $_[0];} else{ die"fix_fn() needs 1 arg : $!";} @fn_arr = split_on_suffix( $fn ); $fn = replace_bad_chars( $fn_arr[0] ); $fn = $fn . '.' . $fn_arr[1]; return( $fn); } sub replace_bad_chars { # string my($fn); my(@fn_arr); if(defined($_[0])){ $fn = $_[0];} else{ die"replace_bad_chars() needs 1 arg : $!";} @fn_arr = split( /\W+/ , $fn); $fn = join( '_' , @fn_arr ) ; return( $fn ); } sub split_on_suffix { # string my($fn); my($suffix); my(@fn_arr); if(defined($_[0])){ $fn = $_[0];} else{ die"strip_suffix() needs 1 arg : $!";} @fn_arr = split( /\./ , $fn ); $suffix = pop( @fn_arr ); $fn = join( '.' , @fn_arr ); @fn_arr = ( $fn , $suffix ); return( @fn_arr ); }