On Wednesday, 6 December 2017 at 09:16:56 UTC, Andrea Fontana wrote:
On Tuesday, 5 December 2017 at 17:21:29 UTC, Vino wrote:
Hi All,

Is there any better ways to get the size of folders , The below code perfectly works , but i need return type as Array!(Tuple!(string, string)) rather then using the "Result.insertBack(d); Result.insertBack(to!string(SdFiles[].sum))" as per the below example.

E.g:
Array!(Tuple!(string, string)) Result;
Result = (d, to!string(SdFiles[].sum));

Program:
import std.algorithm: filter, map, sum, uniq;
import std.container.array;
import std.file: dirEntries, SpanMode, isDir, isFile;
import std.stdio: writeln;
import std.typecons: tuple, Tuple;
import std.conv: to;
/******************************************/
/* Sub Function : Size of Dir List        */
/******************************************/
auto mSize () {
        string FFs = "C:\\Temp\\BACKUP";
        Array!string Result;
auto dFiles = Array!string ((dirEntries(FFs, SpanMode.shallow).filter!(a => a.isDir)).map!(a => a.name));
        foreach (d; dFiles[])   {
auto SdFiles = Array!ulong((dirEntries(d, SpanMode.depth).filter!(a => a.isFile)).map!(a => a.size)); if (SdFiles[].sum / 1024 / 1024 > 30) { Result.insertBack(d); Result.insertBack(to!string(SdFiles[].sum)); }
                                                                }
                return Result;
}

void main() {
writeln(mSize[]);
}

From,
Vino.B

Something like:

auto mSize () {
        string FFs = "C:\\Temp\\BACKUP";
        
   return dirEntries(FFs, SpanMode.shallow)
   .filter!(a => a.isDir)
.map!(a => tuple(a.name, a.dirEntries(SpanMode.depth).filter!(a=>a.isFile).map!(a => a.size).sum))
   .filter!(a => a[1] > 1024*1024*30)
   .map!(a => tuple(a[0], a[1].to!string))
   .array;
}

?

Hi Andrea,

Thank you very much, as your code is pretty good for our scenario, just one request, the above is a part of our main code where we have many such sub code and all of our sub code use the container array(std.container.array) rather than standard array(std.array), so can you please guide me on how to implement the same code using the container array.

From,
Vino.B.

Reply via email to