in reply to Reading and writing CSV

hola dudes, dudettes, others;

i know this is late, but a wee scripty follows which actually does what Concept99 wants. and a little more; filecounts, directory counts for the paths to be examined. remove to taste.

i use Adam Rich's Win32::DirSize because i gather from the Concept99's posting's paths that we are on a Win32 system and also, incidentally, it is > 50% faster, does the formatting etc and more.

Concept99 need not read & reread mastering RegeXes, admirable tho the book is, to parse a csv. is anything simpler to parse than a csv of directory paths? well, yes, i hope that none of the paths have commas in them etc. but do i need a module to write a csv file? no sirree. perl is practical enough by itself. here goes:

use Win32::DirSize; # >= 50% faster than file::find chomp(my @lines = (<DATA>)); my @pathsets = map { [ split ",", $_ ] } @lines; my @dstats; push @dstats,join ",",("Directory", "Size", "FileCount", "DirCount"); foreach my $pathset (@pathsets){ foreach my $path (@{$pathset}){ if (dir_size($path, my $dstat) == DS_RESULT_OK){ my $size = best_convert(my $unit, $dstat->{HighSize}, $dstat->{LowSize}); my $fcnt = $dstat->{FileCount}; my $dcnt = $dstat->{DirCount}; push @dstats, join ",",($path, sprintf("%7.4f %s", $size, $uni +t),$fcnt, $dcnt); } push @dstats, undef; } } map { print } grep { defined } @dstats; __DATA__ \\ooby\dooby$\stodge,\\ooby\ccc$\etc\lib \\foo\bar$\wufnik,\\foo\bar$\id
which will spit out the results for each dir encountered. hope it helps,

...wufnik

-- in the world of the mules there are no rules --

Replies are listed 'Best First'.
Re: Re: Reading and writing CSV
by Anonymous Monk on Jun 05, 2003 at 15:32 UTC
    As I said earlier, I'm new to Perl, so I am not quite sure how to install "Win32-DirSize-1.00.tar.gz" file I downloaded. I am running ActivePerl 5.6 on a Win2k Box. When I use nmake and try to install this, I get the following response:
    cp csvtest.pl blib\lib\Win32\csvtest.pl cp dirsize.pl blib\lib\Win32\dirsize.pl cp csvtest2.pl blib\lib\Win32\csvtest2.pl cp test2.pl blib\lib\Win32\test2.pl cp DirSize.pm blib\lib\Win32\DirSize.pm AutoSplitting blib\lib\Win32\DirSize.pm (blib\lib\auto\Win32\DirSize) cp try.pl blib\lib\Win32\try.pl C:\Perl\bin\perl.exe -IC:\Perl\lib -IC:\Perl\lib C:\Perl\lib\E +xtUtils/xs ubpp -typemap C:\Perl\lib\ExtUtils\typemap DirSize.xs > DirSize.xsc & +& C:\Perl\ bin\perl.exe -IC:\Perl\lib -IC:\Perl\lib -MExtUtils::Command -e mv Dir +Size.xsc D irSize.c Please specify prototyping behavior for DirSize.xs (see perlxs manual) cl -c -nologo -O1 -MD -Zi -DNDEBUG -DWIN32 -D_CONSOLE -DNO_ST +RICT -DHAV E_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT +_READFIX - O1 -MD -Zi -DNDEBUG -DVERSION=\"1.00\" -DXS_VERSION=\"1.00\" -IC: +\Perl\lib\ CORE DirSize.c 'cl' is not recognized as an internal or external command, operable program or batch file. NMAKE : fatal error U1077: 'C:\WINNT\system32\cmd.exe' : return code ' +0x1' Stop.
    I'd appreciate any suggestions if you have em.