in reply to how to get the parent directory name?

Or do it the other way. Run your script at the top level of your music and use relative paths below that:
use File::Spec qw/splitdir/; my @files = glob "*/*/*"; foreach my $file (@files) { my ($artist, $album, $track) = File::Spec->splitdir($file); # Do something to $file using these vars and a module to # get/set tags }
Remember, your current working dir is a global variable, which lots of code relies on (all your open calls, for instance). I've always regretted chdiring around in a script. It's generally easier to work with relative paths from where you are.

Replies are listed 'Best First'.
Re^2: how to get the parent directory name?
by jhourcle (Prior) on Dec 08, 2006 at 14:09 UTC

    For cases like this, I work from the top, and just keep track of where I've been:

    Yes, it seems like it's more work, but it allows you do special handling as you enter/leave each directory -- maybe you want to create playlists for each artists, etc. And I'm actually dealing with millions of files (scientific data, not music albums)

    okay ... I don't actually use code like that -- it's too repetitive ... I use recursive functions (as it's much more than 3 levels deep) and a dispatch table for the directories that need to be handled in a special manner ... but the above at least explains the basic methodology and should be easier to follow.

      Thanks all of you for the resposes!

      I used this code ast a starting point, and I'm almost there, thanks!

      I had to change
      next if (-D
      into
      next if (!-d
      I guess that's just my version of perl?