#!/perl -w use strict; ##Code is tested on winxp with perl 5.8## my $path = "c:\\"; my @files; #Open the directory opendir(AMHANDLE,$path); #iterate over the file handle while(my $file = readdir(AMHANDLE)) { #print $file ."\n"; #If the file is a folder then just echo it if(-d $path.$file) { print "$file is a folder\n"; } else { #Else push it onto the files array push @files,$file; } } #Close the handle closedir(AMHANDLE); #Echo the contents of the @files array foreach my $item(@files) { print $item . "\n"; }