AUTOLOAD; $|++; use strict; use Win32; use Time::localtime; use Win32::Lanman; use Win32::NetAdmin; use Win32::OLE qw ( in with ); use Win32::OLE::Const 'Microsoft Excel'; my $app = 'Excel.Application'; my $xls = Win32::OLE -> GetActiveObject ( $app ) || Win32::OLE + -> new ( $app ); die "\nCannot start $app! : $!\n" unless $xls; $xls->{Visible} = 1; $xls -> {SheetInNewWorkbook} = 1; die "\nCannot start $app! : $!\n" unless $xls; my $xls_book = $xls -> Workbooks -> Add ( ); my $sheet = $xls-> Worksheets ( "Sheet1" ); $xls_book ->{Name} ="$ARGV[0]"; $xls -> ActiveWorkbook -> SaveAs( $ARGV[0] ); my $row =2; print "\nAccessing Server: " . "\\\\" . $ARGV[0]; if (Win32::Lanman::NetShareEnum("\\\\"."$ARGV[0]", \ my @shares)) { print " Successfully\n"; my $ShareCount = 0; my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject'); my $TotalSize=0; for my $Share (@shares) { my $col =1; next if ( ($Share->{path}) =~ /^c/i); next if ( ($Share->{netname})=~ /ipc\$|rpc\$|netlogon\$|admin\ +$|^CDROM|^\w\$/i); my $Target = "\\\\"."$ARGV[0]" . "\\" . $Share->{path}; $Target =~ s/:/\$/; if (opendir (DIR, "$Target")) { print ++$ShareCount . ") $Share->{path}, $Target, $Share +->{netname}\n"; &Prep_Xls; $sheet-> Cells ($row,$col++)-> {value}="$Target"; my $d = $fs->GetFolder("$Target"); my @folders = $fs->GetFolder("$Target" ); my $fCount =0; my $sCount =0; while( @folders ) { my $folder = pop @folders; $fCount += $folder->Files->Count; $sCount += $folder->SubFolders->Count; for my $subFolder ( in $folder->SubFolders ) { $fCount += $subFolder->Files->Count; push @folders, $_ for in $subFolder->SubFolders ; $sCount += $subFolder->SubFolders->Count; } } my $Size = $d->size(); print " ( Size : " . $Size. " Files : $fCount, folders : $ +sCount)\n"; $sheet-> Cells ($row,$col++)-> {value}=$Size; $sheet-> Cells ($row,$col++)-> {value}=$fCount; $sheet-> Cells ($row,$col++)-> {value}=$sCount; $sheet-> Cells ($row++,$col++)-> {value}="$Share->{remark} +"; close (DIR); } else { print "\nError : $Target\n"; } } print "\nTotal number of shares = $ShareCount\n"; $sheet-> Cells (++$row,1)-> {value}="Total number of shares = $Sha +reCount"; } $xls -> ActiveWorkbook -> SaveAs( $ARGV[0] ); undef $xls_book; undef $xls; sub Prep_Xls { $sheet-> Columns ("A:A")->{ColumnWidth} = "55"; $sheet-> Cells(1,1)->Font->{FontStyle}='bold'; $sheet-> Cells(1,1)->{value}='UNC share path'; $sheet-> Columns ("B:B")->{ColumnWidth} = "20"; $sheet-> Cells(1,2)->Font->{FontStyle}='bold'; $sheet-> Cells(1,2)->{value}='Size'; $sheet-> Columns ("C:C")->{ColumnWidth} = "20"; $sheet-> Cells(1,3)->Font->{FontStyle}='bold'; $sheet-> Cells(1,3)->{value}='Num of Files'; $sheet-> Columns ("D:D")->{ColumnWidth} = "20"; $sheet-> Cells(1,4)->Font->{FontStyle}='bold'; $sheet-> Cells(1,4)->{value}='Num of Folders'; $sheet-> Columns ("E:E")->{ColumnWidth} = "20"; $sheet-> Cells(1,5)->Font->{FontStyle}='bold'; $sheet-> Cells(1,5)->{value}='Remarks'; }
janitored by ybiC: Balanced <readmore> tags around long codeblock, as per Monastery convention
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |