sub callback_readfiles {   my ($folder, $proc, @param) = @_;   my $count = 0;   my $dir = undef;   if(opendir($dir, $folder))   {      while(defined(my $file = readdir($dir)))      {         my $filepath = "$folder/$file";         next if $file =~ /^\.\.?$/;         next if -d $filepath;         $proc->($filepath, @param) if $proc;         $count++;      }      closedir($dir);   }   return $count; } sub get_filename {   my ($file) = @_;   $file =~ s!\\!/!g;   my @parts = split(/\//, $file);   return pop @parts; } use constant FOLDER_FOLDERIMAGES => $Vars::CONFIG{'FOLDER_SKIN'}.'/Images/Folders'; use constant FOLDER_ICONWIDTH => 20; use constant FOLDER_ICONHEIGHT => 20; use constant FOLDER_MAXICONCOL => 5; use vars qw($FOLDERCOL $FOLDERROW); $FOLDERCOL = 0; $FOLDERROW = 0; sub enum_foldericons_cb {   my ($filename, $retval) = @_;   my %data = ();   $data{FOLDERICONX} = FOLDER_ICONWIDTH;   $data{FOLDERICONY} = FOLDER_ICONHEIGHT;   $data{FOLDERICONSRC} = $filename;   $data{FOLDERICONALT} = Global::get_filename($filename);   $retval->[$FOLDERROW] = {} unless defined $retval->[$FOLDERROW];   $retval->[$FOLDERROW]->{FOLDERICONS_COLS} = [] unless defined $retval->[$FOLDERROW]->{FOLDERICONS_COLS};   push @{$retval->[$FOLDERROW]->{FOLDERICONS_COLS}}, \%data;   $FOLDERCOL++;   if($FOLDERCOL >= FOLDER_MAXICONCOL)   {      $FOLDERROW++;      $FOLDERCOL = 0;   } } sub enum_foldericons {   my ($obj, $tpl) = @_;   my @loop = ();   Global::callback_readfiles(FOLDER_FOLDERIMAGES, \&enum_foldericons_cb, \@loop);   $tpl->param(FOLDERICONS_ROWS => \@loop); }