Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

simple bash script question



sorry i meant:


#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
my $oldext = " ";
my $newext = "";
my $location = defined $ARGV[0] ? $ARGV[0] : "./";
opendir(DIR, $location);
for (readdir(DIR)) {
    if (/$oldext/) {
        my $newfile = $_;
        $newfile =~ s/ //g;
        warn "Renaming file $_ to $newfile \n";
        if (! -e $newfile){
            move ($_, $newfile);
        } else {
            warn "File $newfile already exists ";
            next;
        }
    }
}
closedir(DIR);



On Wed, Jan 25, 2006 at 07:40:06PM -0500, Joshua D. Abraham wrote:
> Why not something like this?
> 
> #!/usr/bin/perl
> #rename.pl
> use strict;
> use warnings;
> use File::Copy;
> my $location;
> my $oldext;
> my $newext;
> if (@ARGV == 2 or @ARGV == 3) {
>     $oldext = $ARGV[0];
>     $newext = $ARGV[1];
>     $location = defined $ARGV[2] ? $ARGV : "./";
> } 
>  else {
>     die "Usage: $0 [oldext newext [directory]]\n";
> }
> opendir(DIR, $location);
> for (readdir(DIR)) {
>     if (/$oldext$/) {
>         my $newfile = $_;
>         $newfile =~ s/$oldext$/$newext/;
>         warn "Renaming file $_ to $newfile \n";
>         if (! -e $newfile){
>             move ($_, $newfile);
>         } else {
>             warn "File $newfile already exists ";
>             next;
>         }
>     }
> }
> closedir(DIR);
> 
> 
> --Josh Abraham
> 
> 
> On Wed, Jan 25, 2006 at 07:35:46PM -0500, Rajiv Aaron Manglani wrote:
> > >I'm in the middle of moving a whole slew of mp3s/.oggs to my freshly
> > >modded xbox, however i've run into the snag of the xbox filesystem
> > >(fatx) not liking certain charaters/filename lengths i have on my
> > >desktop.
> > ...
> > >any ideas? better ways to do this?
> > 
> > http://detox.sourceforge.net/
> > 
> > "Detox is a utility designed to clean up filenames. It replaces  
> > difficult to work with characters, such as spaces, with standard  
> > equivalents. It will also clean up filenames with UTF-8 or Latin-1  
> > (or CP-1252) characters in them." ... "It was originally a personal  
> > project, written a few years ago to clean up the names of MP3s ripped  
> > under Windows."
> > 
> > eg:
> > 
> > $ touch test\ \(1\).foo
> > $ ls *foo
> > test (1).foo
> > $ detox -n *foo
> > test (1).foo -> test-1-.foo
> > 
> > 
> > 
> > _______________________________________________
> > Discuss mailing list
> > Discuss at blu.org
> > http://olduvai.blu.org/mailman/listinfo/discuss
> _______________________________________________
> Discuss mailing list
> Discuss at blu.org
> http://olduvai.blu.org/mailman/listinfo/discuss




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org