my $folder = Win32::OLE->CreateObject('Scripting.FileSystemObject')->GetFolder($TargetPath); my $file_count = $folder->Files()->Count(); my $folder_count = $folder->SubFolders()->Count(); my $total = $file_count + $folder_count;