Hi, So I have a better version. But if it goes down in the recursion tree, at the end it goes into infinite loop, because there is no other dir inside the last dir in the tree. At this point it has to step back. But instead of stepping back it goes into infinite loop. Why?
sub Traverse { if( opendir(DIR, $dir) ) { my @files = readdir(DIR); closedir(DIR); foreach my $file (@files) { # generate XML here $actualdir = $dir . "\\" ; next if (($file eq '.') || ($file eq '..')); print $file; if((-d $actualdir.$file) and ($file !~ /^\.\.?$/) and ($file ne ".") and ($file ne "..")) { # make dir branch $newpath = $actualdir.$file; $writer->startTag("Folder", "Name" => $newpath); Traverse($newpath, $writer); $writer->endTag("Folder"); } else { # make file branch $writer->emptyTag("Object", "Name" => $actualdir.$file); } } } } Tamas