Front page | perl.perl6.users |
Postings from October 2022
Re: folder size
Thread Previous
|
Thread Next
From:
ToddAndMargo via perl6-users
Date:
October 24, 2022 19:52
Subject:
Re: folder size
Message ID:
d3603713-bbbc-2302-3bd6-ca2f4411e06b@zoho.com
>> On Sun, Oct 23, 2022 at 9:56 PM ToddAndMargo via perl6-users
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>>
>> On 10/22/22 21:30, ToddAndMargo via perl6-users wrote:
>> > Hi All,
>> >
>> > Does Raku have a folder size command (including sub
>> > folders) or is that a system call?
>> >
>> > Many thanks,
>> > -T
>>
>> My final code:
>>
>>
>> sub RunCmd( Str $CommandStr, Bool $EchoOff = False ) {
>> my Str $BatFile = $PathIAm ~ ".bat";
>> my Str $RtnStr;
>> my Str $CmdStr = "";
>>
>> if $EchoOff { $CmdStr = Q[@echo off] ~ "\n"; }
>> $CmdStr = $CmdStr ~ $CommandStr ~ "\n";
>> # print "$CmdStr";
>>
>> spurt( $BatFile, $CmdStr );
>> $RtnStr = qqx { $BatFile };
>> # print "$RtnStr\n";
>> return $RtnStr;
>> }
>>
>>
>> sub DirectoryExists( Str $DirPath --> Bool ) { return
>> "$DirPath".IO.d.Bool; }
>>
>> sub FolderSize( Str $FolderPath --> Int ) {
>> # dir . /s /A:-D /d /a | raku -e "say lines[*-2].words[2]"
>> # 3,275,848,795
>> # > my Str $x="123,456,789"; $x~~s:g/","//; say $x; $y=$x.Int;
>> say $y
>> # 123456789
>> # 123456789
>>
>> my $SubName = &?ROUTINE.name;
>> my Str $RtnStr = "";
>> my Str $ErrMsg = "";
>> my Int $Size = 0;
>>
>> if not DirectoryExists( $FolderPath ) {
>> $ErrMsg = "$IAm\:$SubName error: FolderPath <$FolderPath>
>> doesn
>> not exist\n\n";
>> MessageBox $IAm, $ErrMsg, MB_ICONERROR, MB_OK;
>> print $ErrMsg;
>> return 0;
>> }
On 10/24/22 12:26, William Michels via perl6-users wrote:
> Hi Todd,
>
> Thanks for the code! Unfortunately I see this error:
>
> Variable '$PathIAm' is not declared. Perhaps you forgot a 'sub' if
> this was intended to be part of a signature?
> at -:3
> ------> [32m my Str $BatFile = [33m⏏ [31m$PathIAm ~ ".bat"; [0m
>
>
It is a global.
my $PathIAm = $?FILE;
$PathIAm ~~ s:global| '/' |\\|;
( my Str $IAm = $PathIAm ) ~~ s| .* "\\" ||;
I am not using the *,tmp file that Windows likes
to create, but using my own file name instead.
I should have included that.
The reason for creating a .bat file for a system
call is that Raku 's system call coughs on spaces.
I did report it. I have not checked to see if
it was fixed. I like being able to just write
out the call like it would be on the command line
anyway. And it is fast.
Thread Previous
|
Thread Next