Hi, I'm fairly new to perl, and have difficulties to get the parent diretory name.
What I want to do is:

I have a very large collection of music files from which a vast amount neither is tagged correctly or tagged at all.
Also their file name is not right. But I do now that the directory structure is right. The 1st dir is artist, this contains subdirs with the albums, and the filenames contains at least the trackname but sometimes also other info.
(ie: /Celtic Frost/Into The Pandemonium/02\ -\ Mesmerized.mp3

So I need a script that reads a files name, the name of it's parent directory and the directory above that, and than examins the file name to substract the trackname. That results in 3 variabels from which I can correctly rename the file, and tag the file.

From wihtin the example directory above I tried :
my $artistdir=opendir(DIR, '..'); my $albumdir=opendir(DIR, '.'); print "$artistdir\n"; print "$albumdir\n";
Clearly that does not work.

In reply to how to get the parent directory name? by juro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.