in reply to Duplicates in Win32::DirSize

Code?

Replies are listed 'Best First'.
Re^2: Duplicates in Win32::DirSize
by Real Perl (Beadle) on Aug 19, 2005 at 19:08 UTC
    ok, this is the way I use it:
    foreach (@arraydirectory){ my $cleansource = $source; $cleansource .= "\\"; $cleansource +.= $_; $sourceResult = dir_size($cleansource, $sourceDirInfo,); $sbyte += $sourceDirInfo->{DirSize}; $sourceSize = best_convert($sourceSizeUnit, $sourceDirInfo->{H +ighSize}, $sourceDirInfo->{LowSize},); my $s = $sourceSize; $s .= $sourceSizeUnit; $table->add($_); $table->itemCreate($_, 0, -text => $_); $table->itemCreate($_, 1, -text => $s); }#foreach
    Hope this helps,
    Claire

      For clarification, what kind of "hurtle" are you seeing? Is it messing up when it tries to itemCreate() because of the duplicate name? Is it reporting a wrong size? Are we talking duplicate full paths or just duplicate bottom-level folder names (c:/foo/bar/baz and c:/windows/baz, for instance)?

      While I'm here, you could make the code a little more concise:

      # Line 2 my $cleansource = "$course\\$_"; # or: my $cleansource = $course . "\\" . $_; # Lines 6/7 my $s = "$sourceSize$sourceSizeUnit"; # or: my $s = $sourceSize . $sourceSizeUnit

      Using x= (with x being some operator) is only more efficient when working with one additional value. Which looks better to you:

      $x = $a; $x += $b; $x += $c; $x += $d; $x = $a + $b + $c + $d;

      The latter involves less typing, looks much clearer, and is likely more efficient. Sorry to be nitpicky. I'm often anal about grammar and all things related (both in code and in language)

      [id://wink] waits for someone to find a grammar mistake in this reply (no, I didn't place one intentionally for anyone to find, but I likely made one). ;)

        Dear Wink,
        Thank you very much to show me the efficient way of doing things. I am quite new at programming and I'm learning Perl on my own!! (with the Monks).
        Any way, I don't know how to clarirfy the hurtle. One thing I know is that if I have "user1, user2, user3 and then user1 again, the method calculates the right size for user1 then user2 and user3 and then gives me a long error message at the DOS prompt and eventhough the program goes on and displays what was calculated (that is done with the make_table method that I am not showing here), the program is not functional anymore and has to be closed. The duplicates are only in the user names. For example, I ask my program to go get the size for: C:\documents and settings\desktop\testfolder\ and then in a for loop I append the name of the folder under testfolder.
        I though of dealing with the duplicates before it even tries to calculate anything by sorting the array and checking if I have duplicates before I launch the method, but I have another issue with that. The issue is really embarrassing because Perl execute the if statement and the else statement also!
        Here is the all method:
        sub create_file_for_batch{ if($dest ne "" && $source ne "" && $logpath ne "" && length($sourc +etext)!=1){ $sourcetext=$sourcetextentry->get('1.0','end'); $original_dest = $dest; $dest =~s/\//\\/g; $original_source = $source; $source =~s/\//\\/g; $switches=""; save_switches(); print LOG ("The destination path was: $dest\n The source path was: $source\n The path for the log file is: $logpath\n The users are: $sourcetext\n"); @arraybatch = split /,|\n/, $sourcetext;#splits what is in the + variable $len = @arraybatch; for($i=1; $i<$len; $i=$i+2){ $arraybatch[$i] =~s/\G //g;#gets rid of the space in front $arraybatch[$i] =~s/ /_/g;#put _ in place of the space bet +ween the name push @arrayfilename, $arraybatch[$i]; }#for for($i=0; $i<$len; $i=$i+2){ push @arraydirectory, $arraybatch[$i]; }#for @sortedarraydirectory = @arraydirectory;#makes a copy of the a +rraydirectory so I can sort @sortedarraydirectory= sort @sortedarraydirectory;#sort the co +pied array $len = @sortedarraydirectory; for ($i=0; $i<$len; $i++){ if ($sortedarraydirectory[$i] ne $sortedarraydirectory[$i+ +1]){ make_table(); $notebook->pageconfigure('page1', -state=>'normal'); $notebook->pageconfigure('page2', -state=>'normal'); }else{ $dialog = $page3-> Dialog( -title => 'Alert', -text => "$sortedarraydirectory[$i] is a duplicate. Pl +ease correct the batch file.", -buttons => [ qw(OK) ]) ->Show(); }#else }#for }else{ $dialog = $page3-> Dialog( -title => 'Alert', -text => "Please enter paths for destination, sources and log +file and fill out the text area for batching", -buttons => [ qw(OK) ]) ->Show(); }#else }#create_file_for_batch
        The outside if else statement works just fine it is just the if and else inside that does not act properly.
        I would be very appreciative if you could point out what I am doing wrong, as I am about ready to give up on checking for duplicate all together!
        Thanks,
        Claire