#!perl use strict; use warnings; use File::Find; my $dir = 'c:/My Projects/Perl Scripts/New Folder'; my $directory_count = 0; my $file_count = 0; my $outfile = 'log.txt'; find( sub { # $_ contains the name of the current file # $File::Find::name contains the full path of the current file relative # to the directory given to the find() function # $File::Find::dir contains the name of the current directory if(-d $_){ # if file is a directory $directory_count++; } elsif(-f $_) { # else if file is a plain file $file_count++; } }, $dir ); open my $log, q(>), $outfile or die "Can't create logfile; $!"; print {$log} "Directories: $directory_count\n"; print {$log} "Files: $file_count\n"; close $log;