Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Renaming Files

by blakem (Monsignor)
on Aug 23, 2001 at 03:43 UTC ( [id://107194]=note: print w/replies, xml ) Need Help??


in reply to Renaming Files

Seek enlightenment at Mp3 Renamer.

-Blake

Replies are listed 'Best First'.
Re: Re: Renaming Files
by jmoloug1 (Initiate) on Aug 23, 2001 at 03:52 UTC
    Thanks, but it's not quite what I'm looking for. I need a script that would start at the parent directory and recursively go into each subdirectory. While there, it would use the directory name (but not the full path) as part of the file name. It's a little more tricky than just renaming a couple files.
      Warning, untested code...

      how about something like:

      my $dir = '/my/mp3/directory'; opendir(DIR,$dir) or die "Cannot open $dir: $!"; while(defined($subdir = readdir(DIR))) { next if $subdir =~ /^\./; next unless -d "$dir/$subdir"; opendir(DIR2,"$dir/$subdir") or die "Cannot open $dir/subdir: $!"; while (defined($file = readdir(DIR2))) { next unless $file =~ /\.mp3$/i; my $src = "$dir/$subdir/$file"; my $dest = "$dir/$subdir/${subdir}_$file"; print "renaming $src => $dest\n"; # rename $src, $dest; } }

      -Blake

        Dude, your code rocks! With some quick mods, I also changed all TXT DOC and JPG files in the same directories. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://107194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found