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. Marcelsub 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; } }
In reply to Simple Recursion by mcsonka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |