Hi Perlmonks I'm using that code for doing a recursive file extraction:
sub readin_directory{ if (defined $_[0]){ my @FILEPATHS = @{$_[0]}; #Argument must be a file with nothin +g without an absolute filename each row my @LIST = (); my @FILELIST = (); foreach my $FILEPATH (@FILEPATHS){ print("\nCurrent Filepath: $FILEPATH\n"); #Open file, store every line in an array index position an +d close file opendir (DIR, $FILEPATH) or die "Couldn't open given direc +tory!"; #Open directory @LIST = readdir(DIR); closedir(DIR) or die "Couldn't close directory!"; #Close d +irectory #Test whether file is an xml-file what is compulsory foreach my $FILE (@LIST){ #Recursively invoke function if current file is a dire +ctory #print("Current File: $FILE\n"); if(-d $FILE){ #Don't wanna have current directory and the one be +low next if $FILE =~ /^./; #print("Current Directory: $FILE\n"); push(@FILELIST,@{&readin_directory($FILE)}); + } elsif ($FILE =~ /\.mp3$/i){ chomp $FILE; if ($FILEPATH =~ /\/$/){ $FILE = $FILEPATH.'/'.$FILE; } else{ $FILE = $FILEPATH.$FILE; } push(@FILELIST, $FILE); } } } print("Warning: Folder seems to be empty!\n") unless(@FILELIST +); return \@FILELIST; #Now return array as reference } else{ print("Error: You must specify at least one input directory!\n +"); return 1; } }
sorry for this huge cutout, but I think it's necessary to understand what I want to do and especially the error may be . Okay, actually the "if(-d ...)" doesn't work well. It only recognizes "." and ".." as directory thus effectively nothing because they will be ignored. But when I put out every filename, the direcotries are listed anyway. So why does this pretendingly easy -d not work? I am seeking this source of all evil for a long time... would be great if someone can give me a solution. Thanks. Marcel

In reply to Simple Recursion by mcsonka

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.